posix_getpgid
(PHP 4, PHP 5)
posix_getpgid — Get process group id for job control
Description
int posix_getpgid
( int
$pid
)
Returns the process group identifier of the process
pid
or FALSE
on failure.
Parameters
-
pid
-
The process id.
Return Values
Returns the identifier, as an integer.
Examples
Example #1 Example use of posix_getpgid()
<?php
$pid = posix_getppid();
echo posix_getpgid($pid); //35
?>
Notes
Note:
This is a not POSIX function, but is common on BSD and System V systems. If the system does not support this function, then it will not be included at compile time. This may be checked with function_exists().
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для управления процессами программ
- POSIX
- posix_access
- posix_ctermid
- posix_errno
- posix_get_last_error
- posix_getcwd
- posix_getegid
- posix_geteuid
- posix_getgid
- posix_getgrgid
- posix_getgrnam
- posix_getgroups
- posix_getlogin
- posix_getpgid
- posix_getpgrp
- posix_getpid
- posix_getppid
- posix_getpwnam
- posix_getpwuid
- posix_getrlimit
- posix_getsid
- posix_getuid
- posix_initgroups
- posix_isatty
- posix_kill
- posix_mkfifo
- posix_mknod
- posix_setegid
- posix_seteuid
- posix_setgid
- posix_setpgid
- posix_setrlimit
- posix_setsid
- posix_setuid
- posix_strerror
- posix_times
- posix_ttyname
- posix_uname
Коментарии
This function and posix_getsid can be used to check if a process is alive (since they return FALSE if the process can not be found)
So if you have a PID in a lock file, and you want to know if that process is still running- you can use this code:
$lockfile = sys_get_temp_dir() . '/myScript.lock';
$pid = file_get_contents($lockfile);
if (posix_getsid($pid) === false) {
print "process has died! restarting...\n";
file_put_contents($lockfile, getmypid()); // create lockfile
} else {
print "PID is still alive! can not run twice!\n";
exit;
}
:-) perfect if you need to make sure a cron job or shell script has ended before it can be started again.