0

How can I kill all the processes that a shell script has generated? myscript was run several times and created unwanted processes and I want to kill them. I am running an Ubuntu 20.

123  sh /usr/local/bin/myscript /mnt/local/data_file/data1.txt
312  sh /usr/local/bin/myscript /mnt/local/data_file/data1.txt
452  sh /usr/local/bin/myscript /mnt/local/data_file/data1.txt
455  sh /usr/local/bin/myscript /mnt/local/data_file/data1.txt
1329 sh /usr/local/bin/myscript /mnt/local/data_file/data1.txt

I have tried the solution posted here, and it does not kill them. Could someone kindly help me find an automated way of finding the processes and kill them all?

afp_2008
  • 1,940
  • 1
  • 19
  • 46
  • 1
    Are you trying to do this just once (in which case `kill 123 312 452 455 1329` should work), or are you trying to automate the process cleanup? If the latter, what exactly are you running (note: I recommend the variant in reinierpost's comment), and what exactly happens (e.g. do you get any error messages, etc)? – Gordon Davisson Jan 04 '22 at 04:29
  • 1
    Also, killing a parent process will kill all its child processes UNLESS those child processes were run with the `nohup` command - could those be the ones that are “not working”? If so, no easy answer other than recursion I guess. – racraman Jan 04 '22 at 06:30

1 Answers1

1

Based on the provided details, you can kill them using the pkill --full or simply pkill -f:

pkill -f "sh /usr/local/bin/myscript"

Optionally use pgrep -f against it first to see the matches.

konsolebox
  • 72,135
  • 12
  • 99
  • 105