-
Notifications
You must be signed in to change notification settings - Fork 831
pcntl_wait / pcntl_waitpid: Document the rusage parameter (fixes #861) #4917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6030448
fd20c6a
55c86d4
cb6baa4
b9cb0c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,6 +130,20 @@ | |
| </para> | ||
| </listitem> | ||
| </varlistentry> | ||
| <varlistentry> | ||
| <term><parameter>resource_usage</parameter></term> | ||
| <listitem> | ||
| <para> | ||
| The <parameter>resource_usage</parameter> parameter is set to an | ||
| associative <type>array</type> containing resource usage statistics | ||
| from the child process. | ||
|
|
||
| This is supported either if the wait6 system call is available | ||
| (e.g. on FreeBSD), or on Linux through the raw waitid system call. For | ||
| information on the contents see <function>getrusage</function>. | ||
| </para> | ||
| </listitem> | ||
| </varlistentry> | ||
| </variablelist> | ||
| </para> | ||
| </refsect1> | ||
|
|
@@ -143,12 +157,71 @@ | |
| </para> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="examples"> | ||
| &reftitle.examples; | ||
| <para> | ||
| <example> | ||
|
Comment on lines
+161
to
+163
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless wrapping para tag |
||
| <title><function>pcntl_waitpid</function> example</title> | ||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| function checkChild(int $pid, bool $wait): void | ||
| { | ||
| $flags = ($wait ? 0 : WNOHANG); | ||
| $deadPid = pcntl_waitpid($pid, $status, $flags, $rusage); | ||
| if ($deadPid === -1) { | ||
| $errNo = pcntl_get_last_error(); | ||
| $errMsg = pcntl_strerror($errNo); | ||
| print "PARENT pcntl_waitpid FAILED ({$deadPid}): {$errMsg}\n"; | ||
| } elseif ($deadPid === 0) { | ||
| print "PARENT pcntl_waitpid: No exited children.\n"; | ||
| } else { | ||
| print "PARENT pcntl_waitpid: Child PID {$deadPid} exited with status: " | ||
| . pcntl_wexitstatus($status) ."\n"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation for wexitstatus says:
So, is a |
||
| var_dump($rusage); | ||
| } | ||
| } | ||
| $parentPid = getmypid(); | ||
| $forkedPid = pcntl_fork(); | ||
| if ($forkedPid == -1) { | ||
| die('Could not fork'); | ||
| } else if ($forkedPid) { | ||
| // Parent process | ||
| print "PARENT {$parentPid} has forked {$forkedPid}\n"; | ||
| print "PARENT is checking for exited children\n"; | ||
| checkChild($forkedPid, false); | ||
| // Prevents children remaining as a "zombie process" | ||
| print "PARENT is waiting for a child to exit\n"; | ||
| checkChild($forkedPid, true); | ||
| print "PARENT is checking for exited children\n"; | ||
| checkChild($forkedPid, false); | ||
| print "PARENT is exiting\n"; | ||
| } else { | ||
| // Child process | ||
| $pid = getmypid(); | ||
| print "CHILD {$pid} is sleeping\n"; | ||
| sleep(10); | ||
| print "CHILD is exiting\n"; | ||
| exit(7); | ||
| } | ||
| ]]> | ||
| </programlisting> | ||
| </example> | ||
| </para> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="seealso"> | ||
| &reftitle.seealso; | ||
| <para> | ||
| <simplelist> | ||
| <member><function>pcntl_fork</function></member> | ||
| <member><function>pcntl_signal</function></member> | ||
| <member><function>pcntl_wait</function></member> | ||
| <member><function>pcntl_wifexited</function></member> | ||
| <member><function>pcntl_wifstopped</function></member> | ||
| <member><function>pcntl_wifsignaled</function></member> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering how often this is repeated, an XInclude or XML entity to have consistent wording would be better