Skip to content
Advertisement

Get Children PID using Parent PID from PHP

For context: I am spawning a Java application from PHP, using xvfb-run. Now, this process creates a parent PID for the xvfb-run and couple more children PIDs corresponding to Xvfb and java process.

Using the following command, I have managed to get the parent PID (of xvfb-run):

JavaScript

Now, once the Java process is complete, I will need to kill the Java process, to free up my server resources. (Java application is GUI based, and I have managed to get it working without utilising GUI control, but still I can close it, only by using kill -9 <pid>

Now, from the terminal, I can get the Children pid using:

JavaScript

and, it will return me pids as follows:

JavaScript

However, when I try to do the same using PHP, I cannot get these pid(s) out. I have tried exec, shell_exec, system etc. My attempted script is:

JavaScript

It prints out the following:

JavaScript

What am I missing here ? Any pointer would be helpful. Thanks in Advance

Advertisement

Answer

pgrep -P approach did not work when doing exec inside PHP. So, I used another approach to get children pid(s):

JavaScript

The sample PHP code would be:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement