-2

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.

3
  • ps auxf show you the process tree
    – c4f4t0r
    Dec 6, 2013 at 16:09
  • This doesnt help me. Dec 6, 2013 at 16:19
  • Why not? ps auxf|grep hlds_run should show you the processes you are looking for.
    – etagenklo
    Dec 7, 2013 at 14:42

3 Answers 3

1

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
0

You can use pkill (man) to kill all processes by name.

6
  • I run multiple servers if i use pkill - he killing all processes with name is added after command. I need solution to find another process id by concrete process. Dec 6, 2013 at 16:09
  • You can use the -u option to only kill processes by a certain user.
    – skohrs
    Dec 6, 2013 at 16:11
  • userid is one for all (www-data) Dec 6, 2013 at 16:12
  • Try this ps -ef | grep <unique string you want gone> | cut -b9-14 | xargs kill -9
    – skohrs
    Dec 6, 2013 at 16:14
  • Not work correctly. And maybe is better to know pids of another process by port of (Chief pid) Here is example: if i have server with udp port 27015 (hlds_linux + hlds_run + hlds_run) i need to check hlds_linux(27015) to find pid's of second two hlds_run Dec 6, 2013 at 16:18
0

use ps auxf like i told in my previous comment, you can see an output as follow

 root     13728  0.0  0.0 187448  6408 ?        Ss   16:59   0:00 /usr/sbin/httpd2-prefork -f   /etc/apache2/httpd.conf
 wwwrun   13730  0.2  0.2 197868 17272 ?        S    16:59   0:03  \_ /usr/sbin/httpd2-prefork -f   /etc/apache2/httpd.conf
 wwwrun   13732  0.3  0.2 197116 16548 ?        S    16:59   0:04  \_ /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
 wwwrun   13733  0.2  0.2 197888 17292 ?        S    16:59   0:03  \_ /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
 wwwrun   13734  1.0  0.2 198936 18204 ?        S    16:59   0:15  \_ /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
 wwwrun   13814  1.0  0.2 198164 17532 ?        S    16:59   0:14  \_ /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
 wwwrun   14205  0.2  0.2 198288 17668 ?        S    17:03   0:02  \_ /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
 wwwrun   14206  0.3  0.2 197892 17292 ?        S    17:03   0:04  \_ /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
 wwwrun   14207  0.2  0.2 198980 17984 ?        S    17:03   0:02  \_ /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
 wwwrun   14208  0.3  0.2 198188 17584 ?        S    17:03   0:04  \_ /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
 wwwrun   17125  0.2  0.2 197828 16872 ?        S    17:21   0:00  \_ /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf

In this way you can see which process created others process

1
  • read my last post, i need to find second pids by port of chief pid. (udp port) Dec 6, 2013 at 16:29

Not the answer you're looking for? Browse other questions tagged .