1

This question already has an answer here:

The specific find command I am trying to kill is running inside of a user created script?

I created a script that inside of it, it contains a find command that runs for up to 10 minutes, before I run that same script again, it needs to kill that find command.

marked as duplicate by Arronical, Ravexina, Charles Green, user364819, muru bash Jun 13 '17 at 15:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • pkill/killall, or pgrep/pidof+kill – muru Jun 13 '17 at 15:52
1

pgrep

You can use pgrep with -a switch:

pgrep -a find

it will give you a full command line as well as the process ID:

10838 find / -iname png
10839 find / -iname jpg

then you can decide if it's the one you want to kill or not:

kill 10838

will kill the png one.

pkill

you can also use pkill like this:

pkill -x "find / -iname png"

-x means: Only match processes whose names.

Find child process:

use tree to find your desired process, let's say your script name is "script.sh" you can use pgrep -f script to find it, then pass the output to pstree to get a list of it's child and kill the find process which is the child of your script.

$ pstree -p $(pgrep -f script)
bash(10915)───find(10916)
$ kill 10916
  • -x/--exact is used to perform exact matches. What you're looking for is -f/--full to take the entire command-line into account and not just the executable name. For the last variant you may also find -P/--parent useful. – David Foerster Jun 13 '17 at 15:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.