Results 1 to 5 of 5
I am writing a script that needs to get a pid for a process
I'll use pidof() for that
Then I have to kill the process and everything associated with ...
- 11-02-2008 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 10
Script to kill a process
I am writing a script that needs to get a pid for a process
I'll use pidof() for that
Then I have to kill the process and everything associated with it.
So I must do a "kill -9 pidof()" ........
But the syntax will not work that way.
Any suggestions on how to accomplish this?
Thanks
emp
- 11-03-2008 #2
With the bash shell, putting something in $(...) means that the part between the parentheses is to be executed as a shell command, and the output is to be placed at that point in the overall line.
Example:
lists the names of the non-hidden files in the current directory, sorted by time of most recent modification, so the files which have been modified most recently appear at the beginning.Code:ls -t
lists the name of the single most recently modified non-hidden file in the current directory.Code:ls -t | head -1
displays the first five lines of that file.Code:head -5 $(ls -t | head -1)
will get the pid of the process(es) running a program named fred.Code:pidof fred
does the same, but also includes any instance of bash which is running a script by that name. If you're trying to kill a bash script, you'll want the -s option.Code:pidof -s fred
should do what you want.Code:kill -9 $(pidof -s fred)
Hope this helps.--
Bill
Old age and treachery will overcome youth and skill.
- 11-03-2008 #3Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
You might also try "pkill".
- 11-03-2008 #4
Quoth the highly esteemed burschik:
Absolutely correct. I had no idea that pkill even existed.You might also try "pkill".
emp1953, if you read the man page for pkill, you'll discover a collection of options available for it. Most of them probably won't interest you, but a few of them might.
Worth checking out.--
Bill
Old age and treachery will overcome youth and skill.
- 11-03-2008 #5Just Joined!
- Join Date
- Dec 2007
- Posts
- 10
Thanks all
The "-s" option was the missing part of my puzzle.
Things are working the way they should be.


Reply With Quote