php Function Proc_Get_Status
php function proc_get_status
This article covers php function proc_get_status, a very useful utility that shows you the status of a spawned process.
In php 8.3 this was made public so that you could get an idea of the state of a spawned process without having to poll it every time. It returns a list of key/value pairs, the first one being the exit code of the spawned process. The second is the pid of the process. The remaining items are the status and process information such as the current thread, whether it is protected or not, its uid, and so on.
This function can be used to get an overview of the state of a spawned command that you have started using proc_open(). This is especially helpful if you have opened a bidirectional pipe to that process - then you will want to be sure that the pipe has been closed before calling this function (or else it might hang while waiting for that dead process to finish).
Note that proc_get_status() only works with processes that have been opened via proc_open(). Also note that it will only show you the actual pid of the process, not the grandchild process, if you pass a real command line through proc_open() (not a system() call). On Unix/Linux this can be overcome by prepending "exec" to your command string and then getting the pid of the resulting child process from the result of proc_get_status().