Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill all pid files in a folder

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?

like image 536
Sam Baumgarten Avatar asked Dec 20 '22 10:12

Sam Baumgarten


2 Answers

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
)
like image 88
Faiz Avatar answered Jan 08 '23 00:01

Faiz


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.

like image 45
cyfur01 Avatar answered Jan 08 '23 00:01

cyfur01