4

I have a folder that is filled with .pid files. Each has the PID for a resque worker. How can I kill every PID in that folder from the command line?

4

6 回答 6

4
cat folder/*.pid | xargs kill

should do it?

If you need to specify a signal, for example KILL, then

cat folder/*.pid | xargs kill -KILL

If your pidfiles lack newlines, this may work better:

( cd folder &&
for pidfile in *.pid; do echo kill -QUIT `cat $pidfile`; done
)
于 2013-02-08T05:34:13.207 回答
3

According to the docs it says to use:

ps -e -o pid,command | grep [r]esque-[0-9] | cut -d ' ' -f 1 | xargs -L1 kill -s QUIT

Note: That looks them up by name instead of using the .pid files.

Also, the QUIT signal will gracefully kill them. If you want to forcefully kill them use TERM instead.

于 2013-02-08T06:48:40.577 回答
2

Run the command:

kill `cat folder/*.pid`

If the PID files don't have newlines, then the following should work:

for f in folder/*.pid; do kill `cat "$f"`; done
于 2013-02-08T05:34:30.420 回答
2

Run this - with backticks:

kill -9 `cat /path/*.pid`
于 2013-02-08T05:35:12.467 回答
0

Although the Question is answer but thought that there some many awesome way you can

do some task in linux that what the answer is for exhibiting the power of linux

How abt this

pgrep ruby | xargs ps | grep [r]esque | awk '{print $1}' | xargs kill -9 

NOTE: pgrep is not supported in MAC-OS just thought would be useful to some one

于 2013-02-23T17:52:25.923 回答
0

Leading padding will cause errors. Usesed 's/^ *//g' to remove leading spacing/padding:

ps -e -o pid,command | grep '[r]esque-[0-9]' | sed 's/^ *//g' | cut -d ' ' -f 1 |  xargs -L1 kill -s QUIT
于 2013-11-06T02:46:57.913 回答