aboutsummaryrefslogtreecommitdiffstats
path: root/man2/fork.2
diff options
context:
space:
mode:
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),