How to find all process started by another one in linux [closed]

I run Counter-Strike servers in linux based os (ubuntu, centos) by web script.
I need to find all running process from hlds_linux process (he’s started another two with name hlds_run)

Safe mode is off and i work with shell_exec.
I need to find this process and get his pid’s to can kill them.
Thanks for any help and sorry for my english, im from Bulgaria.

Answer

Try perl, the Swiss Army Chainsaw. Here’s me finding the PID that holds port 80 open, then listing all the children:

[me@lory ~]$ sudo netstat -apn|grep -w 80|grep LISTEN
tcp        0      0 :::80                       :::*                        LISTEN      8308/httpd          
[me@lory ~]$ ps -ef|perl -n -e  '@j=split /  */; print "@j" if ( @j[2]==8308) ; '
apache 9235 8308 0 Dec05 ? 00:01:49 /usr/sbin/httpd
apache 10040 8308 0 Dec08 ? 00:00:41 /usr/sbin/httpd
apache 10477 8308 0 Dec07 ? 00:01:13 /usr/sbin/httpd
apache 10478 8308 0 Dec07 ? 00:01:21 /usr/sbin/httpd
apache 10658 8308 0 Dec08 ? 00:00:29 /usr/sbin/httpd
apache 10662 8308 0 Dec08 ? 00:00:26 /usr/sbin/httpd
apache 10666 8308 0 Dec08 ? 00:00:28 /usr/sbin/httpd
apache 10668 8308 0 Dec08 ? 00:00:35 /usr/sbin/httpd
apache 12694 8308 0 Dec06 ? 00:01:39 /usr/sbin/httpd
apache 12695 8308 0 Dec06 ? 00:01:43 /usr/sbin/httpd
apache 12696 8308 0 Dec06 ? 00:01:39 /usr/sbin/httpd
apache 18671 8308 0 08:41 ? 00:00:18 /usr/sbin/httpd
apache 21585 8308 0 Dec08 ? 00:00:42 /usr/sbin/httpd
apache 22010 8308 0 Dec05 ? 00:01:33 /usr/sbin/httpd
apache 22011 8308 0 Dec05 ? 00:01:49 /usr/sbin/httpd
apache 22012 8308 0 Dec05 ? 00:01:36 /usr/sbin/httpd

If you only want the PIDs:

[me@lory ~]$ ps -ef|perl -n -e  '@j=split /  */; print "@j[1]\n" if ( @j[2]==8308) ; '
9235
10040
10477
10478
10658
10662
10666
10668
12694
12695
12696
18671
21585
22010
22011
22012

Attribution
Source : Link , Question Author : Georgi Rakovski , Answer Author : MadHatter

Leave a Comment