diff --git a/man2/pidfd_open.2 b/man2/pidfd_open.2 index 9443f3baf..7adad55c3 100644 --- a/man2/pidfd_open.2 +++ b/man2/pidfd_open.2 @@ -91,6 +91,27 @@ is Linux specific. Currently, there is no glibc wrapper for this system call; call it using .BR syscall (2). .PP +The following code sequence can be used to obtain a file descriptor +for the child of +.BR fork (2): +.PP +.in +4n +.EX +pid = fork(); +if (pid > 0) { /* If parent */ + pidfd = pidfd_open(pid, 0); + ... +} +.EE +.in +.PP +Even if the child process has already terminated by the time of the +.BR pidfd_open () +call, the returned file descriptor +is guaranteed to refer to the child because +the parent has not yet waited on the child +(and therefore, the child's ID has not been recycled). +.PP The .BR pidfd_send_signal (2) system call can be used to send a signal to the process referred to by