问题
My process forks several times, and each time the child will exec - means I want it to run some other program.
In the main process I open a file descriptor with the open()
syscall.
Would it be correct to give it a flag O_CLOEXEC
so the new program that I run with exec()
wouldn't has the fd resource?
回答1:
Yes, unless you need the program you exec to have access to that file descriptor. You can also close the file descriptor manually in the child process before calling exec, but that's more error prone.
来源:https://stackoverflow.com/questions/15447657/when-should-i-use-o-cloexec-when-i-open-file-in-linux