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
pkill
/killall
, orpgrep
/pidof
+kill
– muru Jun 13 '17 at 15:52