The _exit(2) function is a better choice for exiting a child in many
cases. Most prominently it avoids calls of functions registered with
atexit(3) by the parent.
There are valid reasons to call exit(3) and the example is actually one
of them: flush FILE-based output. Since atexit(3) is never called, we
could just stay with exit(3).
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Message-ID: <tngwcffbrzbfkj6vrxgxpekrp3bzuftdy2mzow56xyfkrcna2w@nbgr2ourerxo>
Link: <https://github.com/shadow-maint/shadow/pull/1171>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
exit(EXIT_FAILURE);
case 0:
puts("Child exiting.");
- exit(EXIT_SUCCESS);
+ fflush(stdout);
+ _exit(EXIT_SUCCESS);
default:
printf("Child is PID %jd\[rs]n", (intmax_t) pid);
puts("Parent exiting.");
.BR clone (2),
.BR execve (2),
.BR exit (2),
+.BR _exit (2),
.BR setrlimit (2),
.BR unshare (2),
.BR vfork (2),