how to exit a child process - _exit() vs. exit
You should definitely use _Exit()
. exit()
calls the functions you added with atexit()
and deletes files created with tmpfile()
. Since the parent process is really the one that wants these things done when it exists, you should call _Exit()
, which does none of these.
Notice _Exit()
with a capital E. _exit(2)
is probably not what you want to call directly. exit(3)
and _Exit(3)
will call this for you. If you don't have _Exit(3)
, then yes, _exit()
is what you wanted.
execvp will exit the child if successfull so you don't have to exit.
On execve failure I simply use exit(EXIT_FAILURE);
in the child.
Edit : i found that after some research : http://www.unixguide.net/unix/programming/1.1.3.shtml
So it's looks like it's better to use _exit()
in a fork child specially when you are in C++ :pThanks for your question i learned something :D