aboutsummaryrefslogtreecommitdiffstats
path: root/man2/fork.2
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-03-30 16:23:04 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-03-30 16:23:04 +0200
commit94b639c1db4dd97b51f02cf76d713e0ac42d2bb9 (patch)
tree89bd80689e7ee39464a1aaad7cc5dc03a04773b1 /man2/fork.2
parent1ae6452e5e978223d8b8c3c2affc6e6d3c215eb5 (diff)
downloadman-pages-94b639c1db4dd97b51f02cf76d713e0ac42d2bb9.tar.gz
fork.2: EXAMPLES: Add simple example using fork(2) without wait(2)
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Diffstat (limited to 'man2/fork.2')
-rw-r--r--man2/fork.237
1 files changed, 36 insertions, 1 deletions
diff --git a/man2/fork.2 b/man2/fork.2
index 3a731f0e71..7260d7db44 100644
--- a/man2/fork.2
+++ b/man2/fork.2
@@ -295,7 +295,42 @@ established using
See
.BR pipe (2)
and
-.BR wait (2).
+.BR wait (2)
+for more examples.
+.PP
+.\" SRC BEGIN (fork.c)
+.EX
+#include <signal.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main(void)
+{
+ pid_t pid;
+
+ if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
+ perror("signal");
+ exit(EXIT_FAILURE);
+ }
+ pid = fork();
+ switch (pid) {
+ case -1:
+ perror("fork");
+ exit(EXIT_FAILURE);
+ case 0:
+ puts("Child exiting.");
+ exit(EXIT_SUCCESS);
+ default:
+ printf("Child is PID %jd\en", (intmax_t) pid);
+ puts("Parent exiting.");
+ exit(EXIT_SUCCESS);
+ }
+}
+.EE
+.\" SRC END
.SH SEE ALSO
.BR clone (2),
.BR execve (2),