Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 02-03-2008, 01:07 AM   #1
Registered: Feb 2007
Distribution: Vector
Posts: 318

Rep: Reputation: 31
one line identify and kill PID (scriptable)

I need to write a one line command to find the PID by process name and kill it.
Here is how I would MANUALLY do it:
MSNTV2:~# ps aux | grep /usr/bin/X11/X
root      4148  0.4 14.2 19600 17876 ?       S<   20:17   0:02 /usr/bin/X11/X -dpi 100 -nolisten tcp
root      4274  0.0  0.4  1916  588 pts/2    R+   20:27   0:00 grep /usr/bin/X11/X
MSNTV2:~# kill 4148
Note that it returns 2 PIDs, one of which is false.
Doing this:
MSNTV2:~# killall X
X: no process killed
MSNTV2:~# killall /usr/bin/X11/X
/usr/bin/X11/X: no process killed
...will not work.

I need a one line command that would get that done, and I could put it into a shell script.
Thanks in advance.
Old 02-03-2008, 01:49 AM   #2
LQ Newbie
Registered: Oct 2006
Location: Las Vegas
Distribution: gentoo,lfs
Posts: 7

Rep: Reputation: 0
kill `pidof aoeu`
pkill aoeu
where aoeu is the name of the process, of course. and note that those aren't single quotes ('), they're grave accents/whatever else they're called (`).

Last edited by Argent; 02-03-2008 at 01:52 AM. Reason: pkill
Old 02-06-2008, 04:47 PM   #3
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Also, changing:
ps aux | grep /usr/bin/X11/X
ps aux | grep /usr/bin/X11/[X]
may help. Then add awk:
ps aux | grep /usr/bin/X11/[X] | awk '{print $2}'
PID=`ps aux | grep /usr/bin/X11/[X] | awk '{print $2}'`
killall $PID
Needless to say, I'm not about to test this on my running system. . . .
Old 02-06-2008, 05:52 PM   #4
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590
Originally Posted by archtoad6 View Post
Also, changing
Well actually Argent was right when he added 'pkill', just for the reason you've shown. While there usually is more than one way to kill things the "problem" is you're suggesting to use 3 binaries where one suffices. With pkill you can select a process by any detail of the process using "-f". If for instance he had two X processes running: "/usr/bin/X11/X -dpi 100 -nolisten tcp" and "/usr/bin/X11/X -nolisten tcp" using 'pkill -9 -f '/X'' would have killed them both while using 'pkill -9 -f 'X -d'' could have only selected the first process.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
kill <pid> does not do anything moskito01 Linux - General 9 08-25-2009 01:20 PM
How to identify a line and replace another string on that line using Shell script? Sid2007 Programming 10 10-01-2007 09:49 PM
kill -9 and respawns as new pid jago25_98 Linux - Software 3 06-18-2007 03:05 PM
kill pid ekdya Debian 3 04-18-2006 06:04 PM
kill pid.... won't work with 'pid' variable given.. sachitha Programming 6 03-06-2006 08:48 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:06 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration