I am using phing and running selenium server via ExecTask. Sometimes I need to stop running server by killing its process.
Is there a possibility in phing of getting PID of process spawned in ExecTask ?
Advertisement
Answer
No, ExecTask cannot give the pid of spawned processes directly. It can only return it’s exit status and output.
Maybe you can modify the command that you run in ExecTask itself to save the pid of spawned process. You can use $!
to get the pid of the most recent background command.
job1 & //start job1 and run in background, end command with & p1=$! //stores the pid echo $p1 //gives pid of job1
When you want to kill the selenium server you can call this in another ExecTask :
pkill pid_to_kill
I am not sure if the changes made in shell environment with ExecTask stay or not. If yes then you can use $p1
. Replace pid_to_kill with $p1 to kill job1. Else you will have to echo the pid and use the value from its output.
Otherwise you will have do pgrep name_of_program
. It will give all processes containing the name. Then you can kill it with pkill
.