I would like to provoke a situation where there is no file descriptor remaining.
I have been thinking about 2 possibilities:
How would you do it?
You can limit the number of file descriptors a process can open under Linux using ulimit.
Executing ulimit -n 3
before running your C program should make it an error to open any more files, since stdin, stdout, and stderr take up the first 3 descriptors.
An example:
$ ulimit -n 3 $ echo > /dev/null zsh: too many open files: /dev/null
The shell process itself attempts to open /dev/null to redirect stdout before closing it there, therefore it gets an error. Your C program will be fed the exact same error the first time it calls fopen, open, socket, etc (or anything that allocates a new file descriptor).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With