From: Tobias Stoeckmann Date: Mon, 13 Jan 2025 16:40:43 +0000 (+0100) Subject: man/man2/fork.2: Add _exit(2) to example X-Git-Tag: man-pages-6.10~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=476bf6d993c13edf8a80c4e874a1d4bf6ff7eb45;p=thirdparty%2Fman-pages.git man/man2/fork.2: Add _exit(2) to example 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 Message-ID: Link: Signed-off-by: Alejandro Colomar --- diff --git a/man/man2/fork.2 b/man/man2/fork.2 index 601391277..6dffec320 100644 --- a/man/man2/fork.2 +++ b/man/man2/fork.2 @@ -326,7 +326,8 @@ main(void) 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."); @@ -339,6 +340,7 @@ main(void) .BR clone (2), .BR execve (2), .BR exit (2), +.BR _exit (2), .BR setrlimit (2), .BR unshare (2), .BR vfork (2),