note 88184 added to function.posix-kill
| From: | Skippy at osu1 dot php dot net | Date: | Wed, 14 Jan 2009 10:12:50 +0000 |
| Subject: | note 88184 added to function.posix-kill | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149184@lists.php.net to get a copy of this message | ||
In order to check the outcome of posix_kill() you can use posix_get_last_error(), which will return
0 (zero) in case of success and a non-zero error code otherwise. Use the number returned by
posix_get_last_error() as a parameter to posix_strerror() to get a human-readable error message
corresponding to that error code.
Please note that a non-zero code from posix_get_last_error() does NOT mean that the pid doesn't
exist; it only means that posix_kill() ran into trouble signalling that process. For example, the
pid may exist but the process is owned by a user other than the one you use to run the code, and
you're not root; in which case you'll get an error saying you're not allowed to
signal that process (operation not permitted).
Accordingly, the code posted by Jille earlier is WRONG. According to the POSIX spec (see errno.h on
your system), EPERM means "operation not permitted". This should NOT be taken as
indication that the pid doesn't exist, it merely means that posix_kill() couldn't signal
that process. If anything, it should be a hint that a process with that pid IS running.
errno.h constant names definitions:
http://www.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html
Unfortunately, PHP does not currently define constants with these names (such as EPERM, ENOENT,
ESRCH etc.) A non-complete subset is defined for socket operations (SOCKET_EPERM for example), but
it doesn't hold all the possible POSIX error constants; ESRCH for instance is of particular
interest for posix_kill(), but SOCKET_ESRCH doesn't exist, because it means "no such
process" and doesn't make sense for sockets.
Solutions:
* Have PHP devs define these constants in a future PHP version.
* Look-up errno.h on your system and define your own constants. You can use a script to parse
errno.h and either define the constants on the fly or generate, once, the PHP code to define them.
Please be advised, however, that relying on a specific errno.h is not portable. Different systems
may have different numeric values for these constants. That's why PHP should be defining the
constants at compilation time and the code should be able to rely on the constant names; only the
names are portable, not the actual values.
----
Server IP: 69.147.83.197
Probable Submitter: 194.88.148.1
----
Manual Page -- http://www.php.net/manual/en/function.posix-kill.php
Edit -- https://master.php.net/note/edit/88184
Del: integrated -- https://master.php.net/note/delete/88184/integrated
Del: useless -- https://master.php.net/note/delete/88184/useless
Del: bad code -- https://master.php.net/note/delete/88184/bad+code
Del: spam -- https://master.php.net/note/delete/88184/spam
Del: non-english -- https://master.php.net/note/delete/88184/non-english
Del: in docs -- https://master.php.net/note/delete/88184/in+docs
Del: other reasons-- https://master.php.net/note/delete/88184
Reject -- https://master.php.net/note/reject/88184
Search -- https://master.php.net/manage/user-notes.php