[PATCH] man/man2/fork.2: Add _exit to example

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The _exit function is a better choice for exiting a child in many
cases. Most prominently it avoids calls of functions registered with
atexit by the parent.

There are valid reasons to call exit and the example is actually one
of them: Flush FILE based output. Since atexit is never called, we
could just stay with exit.

Signed-off-by: Tobias Stoeckmann <tobias@xxxxxxxxxxxxxx>
---
As discussed with alx@ on shadow project, this might still be of
interest to raise awareness of _exit's existence.
---
 man/man2/fork.2 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/man/man2/fork.2 b/man/man2/fork.2
index 601391277..b4f7ffde9 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),
--
2.48.0






[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux