LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Send file output to 'kill' command (https://www.linuxquestions.org/questions/linux-newbie-8/send-file-output-to-kill-command-651448/)

jkarp2112 06-24-2008 11:49 PM

Send file output to 'kill' command
 
Would like to send the output of a text file, in this case a process id, to the 'kill' command so, well, that process would be kill'd ;)

example: if i 'cat something.pid' it outputs the process id i'd like to kill.

of course i could manually do this bit i would like to put it into a bash script.

much tia. - jeff

chrism01 06-25-2008 12:33 AM

pid=`cat something.pid`
kill $pid

or even

kill `cat something.pid`

or

use $() instead of backticks thus

pid=$(cat something.pid) etc etc

bhert 06-25-2008 01:02 AM

I use the script below to kill 3 or 4 numbered process to kill the ones I spawn. Mostly I use it if firefox crashes.

I named the script bomb for fun and put it in my path.

If firefox acts funny, I just type bomb firefox and it's gone.

#!/bin/bash
#script to kill process quickly

kill -9 `ps -e | grep "$*" | cut -d " " -f1` 2>/dev/null || kill -9 `ps -e | grep "$*" | cut -d " " -f2`



-bhert

jkarp2112 06-25-2008 10:27 AM

Excellent - i'll use both to build my script!
 
thanks everyone, this really helped !!

solarkash 06-25-2008 05:17 PM

I'd prefer the xargs

Quote:

cat something.pid | xargs kill


All times are GMT -5. The time now is 10:03 PM.