PHP 7.2.0 Beta 3 Released


(PHP 4, PHP 5)

posix_getppidRestituisce l'ID del processo genitore


int posix_getppid ( void )

Restituisce l'ID del processo genitore per il processo corrente.

add a note add a note

User Contributed Notes 2 notes

divinity76 at gmail dot com
9 months ago
WARNING, when using proc_open, your child will NOT get the parent php process's PID by using posix_getppid() , it will actually get the pid of a shell ( /bin/sh ? ) started by php, which in turn starts the child.  i don't currently have a good workaround for this, but i'm working around it by having the parent write it's pid to a file and having the chidren read the file
divinity76 at gmail dot com
4 months ago
when using proc_open, the child's ppid is NOT your php script, but rather a shell started by proc_open's pid. to get your pid, your proc_open child needs to get the parent's parent's (aka grandparent's) pid. here's a way to do that in PHP on linux:

function posix_getpppid(): int {
    return ( int ) (explode ( " ", file_get_contents ( "/proc/" . posix_getppid () . "/stat" ) ) [3]);

(thanks to TML @ for the technique)

(i said most of this in a previous comment, but i didn't have a good solution for it. now i have. if someone with the privileges read this, can you delete this notice and my previous comment please?)
To Top