Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux open returns 0

The code is like this:

int fd = open(filename, O_RDONLY);

"max open files" is 1024. The process may opened hundreds of files. At the beginning, it works good. After a while, open returns 0. I don't know why. Help!!! Thanks advance!

ps: It's not int fd = open(filename, O_RDONLY) == -1;

like image 571
user2253605 Avatar asked Jan 17 '26 18:01

user2253605


1 Answers

When open returns 0, it's telling you that you should use fd 0 if you want to use the file you just opened.

Did you perchance close stdin?

like image 86
tmyklebu Avatar answered Jan 20 '26 09:01

tmyklebu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!