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?
6 回答
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
)
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.
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
Run this - with backticks:
kill -9 `cat /path/*.pid`
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
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