Kill all pid files in the folder

I have a folder filled with .pid files. Each of them has a PID for the work frame. How can I kill every PID in this folder from the command line?

+4
source share
6 answers

According to the docs it says:

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

Note It looks like a name instead of .pid files.

In addition, the QUIT signal will gracefully kill them. If you want to force them to kill, use TERM instead.

+3
source
 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 does not have line feeds, this might work better:

 ( cd folder && for pidfile in *.pid; do echo kill -QUIT `cat $pidfile`; done ) 
+4
source

Run the command:

 kill `cat folder/*.pid` 

If there are no newlines in the PID files, then the following should work:

 for f in folder/*.pid; do kill `cat "$f"`; done 
+2
source

Run this - with the reverse steps:

 kill -9 `cat /path/*.pid` 
+2
source

Although the question is the answer, but thought there are some amazing ways you can

do some task on linux to answer linux feasibility question

How it works

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

NOTE. pgrep not supported on MAC OS, as soon as it is useful for some

0
source

Leading filling will cause errors. Use sed 's/^ *//g' to remove the leading interval / pad:

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

All Articles