Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F164974605
D27626.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1004 B
Referenced Files
None
Subscribers
None
D27626.diff
View Options
diff --git a/lib/libc/sys/fork.2 b/lib/libc/sys/fork.2
--- a/lib/libc/sys/fork.2
+++ b/lib/libc/sys/fork.2
@@ -28,7 +28,7 @@
.\" @(#)fork.2 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd December 1, 2017
+.Dd April 17, 2021
.Dt FORK 2
.Os
.Sh NAME
@@ -99,6 +99,42 @@
variable
.Va errno
is set to indicate the error.
+.Sh EXAMPLES
+The following example shows a common pattern of how
+.Fn fork
+is used in practice.
+.Bd -literal -offset indent
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main(void)
+{
+ pid_t pid;
+
+ switch (pid = fork()) {
+ case -1:
+ err(1, "Failed to fork");
+ case 0:
+ printf("Hello from child process!\en");
+ exit(0);
+ default:
+ break;
+ }
+
+ printf("Hello from parent process (child's PID: %d)!\en", pid);
+
+ return (0);
+}
+.Ed
+.Pp
+The output of such a program is along the lines of:
+.Bd -literal -offset indent
+Hello from parent (child's PID: 27804)!
+Hello from child process!
+.Ed
.Sh ERRORS
The
.Fn fork
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Aug 6, 4:41 AM (7 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36076911
Default Alt Text
D27626.diff (1004 B)
Attached To
Mode
D27626: fork.2: Add a simple use pattern
Attached
Detach File
Event Timeline
Log In to Comment