Dream
Dream

Reputation: 124

Kill processes run in directory (recursive)

Is it possible to kill all processes run in one directory? Processes have the same user.
For example (runing processes ):

/bin/1/a/p1  
/bin/1/b/p2  
/bin/2/a/p3  

And I want kill all processes from /bin/1/ (/bin/1/a/p1 and /bin/1/b/p2).

Upvotes: 1

Views: 2268

Answers (2)

konsolebox
konsolebox

Reputation: 75488

pkill [-s SIGSPEC] -f '/bin/1/'

Upvotes: 1

devnull
devnull

Reputation: 123518

You can say:

ps aw | awk '/\/bin\/1\// {print $1}' | xargs kill -9

EDIT: In order to ensure that this doesn't kill any unintended command as commented you could say:

ps aw o pid,command | awk '$2 ~ /^\/bin\/1\// {print $1}' | xargs kill -9

Upvotes: 3

Related Questions