1

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.

Seth
  • 58,122

1 Answers1

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
Ravexina
  • 55,668
  • 25
  • 164
  • 183
  • -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