note 93382 added to function.proc-get-status
| From: | MarkSeecof at osu1 dot php dot net | Date: | Mon, 07 Sep 2009 03:36:29 +0000 |
| Subject: | note 93382 added to function.proc-get-status | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160269@lists.php.net to get a copy of this message | ||
On Unix/Linux, if you change the command line you pass to proc_open() just slightly then
proc_get_status() will give you the actual process-id (pid) of your child.
Suppose you wish to run the external command /usr/bin/compress to create a BSD foo.Z file. Rather
than proc_open("/usr/bin/compress /tmp/foo",...) you may invoke proc_open("exec
/usr/bin/compress /tmp/foo",...) and then proc_get_status()['pid'] will be the actual
pid of /usr/bin/compress.
Why? Because the way proc_open() actually works on Unix/Linux is by starting "/bin/sh -c
usercmd userargs...", e.g., "/bin/sh -c /usr/bin/compress /tmp/foo".[Note 1] That
means normally your command is the child of the shell, so the pid you retrieve with
proc_get_status() is the pid of the shell (PHP's child), and you have to fumble around trying
to find the pid of your command (PHP's grandchild). But if you put "exec" in front
of your command, you tell the shell to *replace itself* with your command without starting another
process (technically, to exec your command without forking first). That means your command will
inherit the pid of the shell, which is the pid that proc_get_status() returns.
So if you would like the actual pid of the process running your command, just prepend "exec
" to your proc_open() command argument then retrieve the pid using proc_get_status().
This also makes proc_terminate() and proc_close() work more like you might prefer, since they will
affect the actual process running your command (which will be a child process rather than a
grandchild process).
[Note 1] My guess is that the PHP developers want the shell to expand wildcards in path/filenames.
----
Server IP: 66.207.199.35
Probable Submitter: 71.197.182.25
----
Manual Page -- http://www.php.net/manual/en/function.proc-get-status.php
Edit -- https://master.php.net/note/edit/93382
Del: integrated -- https://master.php.net/note/delete/93382/integrated
Del: useless -- https://master.php.net/note/delete/93382/useless
Del: bad code -- https://master.php.net/note/delete/93382/bad+code
Del: spam -- https://master.php.net/note/delete/93382/spam
Del: non-english -- https://master.php.net/note/delete/93382/non-english
Del: in docs -- https://master.php.net/note/delete/93382/in+docs
Del: other reasons-- https://master.php.net/note/delete/93382
Reject -- https://master.php.net/note/reject/93382
Search -- https://master.php.net/manage/user-notes.php