Geeks, I seek your help.
In my bash script I will need to kill a process and all its children - so, given a parent pid(2288 in this case) & I need to use that parent pid to find child PIDs, put them in a list and then kill them. I have tried the code below…
pstree -p | grep 2288
…but its output has child PIDs embeded within alphabetic characters, as you can see below…
S90service(2288)—-bash(2290)—-php(2291)
Is there a command, or programmatic way I can use to extract PIDs, and put them in a space-separated list ??
Please note that at present I am using…
(1)
pgrep -d’ ‘ -f partial-name-of-process
…to put the PIDs of the parent and its children into a space-separated list, and then kill them. I want to abandon this because of the real possibility of accidentally killing other processes whose names may match partial-name-of-process, and,
(2)
I have tried various other suggested techniques such as regex expressions with awk ‘printf $1’ etc, to extract PIDs from the output of pstree or ps, but most of these suggestions only work on the command line and fail when put to work inside a script. I will be very appreciative and thankful in advance if some geek somewhere can help with a simple technique to extract child PIDs for a given parent pid, and put them into a space-separated list. (My scripts are in bash, on Centos)