thanvi
thanvi

Reputation: 19

Does kill command kill processes specific to a path in linux

I have seen many discussions here on kill command. But my confusion is different. I have many processes with the same name and I have to automate the killing. Hence I can't use the pid. So is it possible that if I go to a specific path and use kill <pname> then only the process related to that path will get killed?
Or is there some way to incorporate the path name in kill command?

Upvotes: 1

Views: 2430

Answers (2)

Ze_Gitan
Ze_Gitan

Reputation: 224

Instead of using a pid, you could always use the pkill command and have it check against some regular expression. If you pass it the -f flag, it allows you to check against the entire command line rather than just the process name.

Something like this would probably do the trick:

pkill -TERM -u username -f "mwhome.*weblogic\\.NodeManager" 

-f is where you would pass in your regex
-u is also useful so that you only affect pid's running as specific users

Upvotes: 5

Kordi
Kordi

Reputation: 2465

No, but you when you start the process with

yourcommand & echo $!

or wrap it in a small script

#!/bin/bash
yourcommand &
echo $! >/path/to/pid.file

you can save the pid. And then kill the process with this pid. This is the normal way how to manage the processes. If you look in the normal init.d scripts of perhaps nginx, they do it the same way. Just saving the pid in a file, and at stopping just read the pid and kill the process.

Upvotes: 1

Related Questions