Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F146749482
D31425.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
979 B
Referenced Files
None
Subscribers
None
D31425.id.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 August 2, 2021
+.Dd August 5, 2021
.Dt FORK 2
.Os
.Sh NAME
@@ -172,11 +172,28 @@
{
pid_t pid;
+ /*
+ * If child is expected to use stdio(3), state of
+ * the reused io streams must be synchronized between
+ * parent and child, to avoid double output and other
+ * possible issues.
+ */
+ fflush(stdout);
+
switch (pid = fork()) {
case -1:
err(1, "Failed to fork");
case 0:
printf("Hello from child process!\en");
+
+ /*
+ * Since we wrote into stdout, child needs to use
+ * exit(3) and not _exit(2). This causes handlers
+ * registered with atexit(3) to be called twice,
+ * once in parent, and once in the child. If such
+ * behavior is undesirable, consider
+ * terminating child with _exit(2) or _Exit(3).
+ */
exit(0);
default:
break;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 6, 6:50 AM (3 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29305811
Default Alt Text
D31425.id.diff (979 B)
Attached To
Mode
D31425: Some clarifications for fork(2) and _Exit(3) man pages
Attached
Detach File
Event Timeline
Log In to Comment