Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill child processes in Bash? [duplicate]

I am trying to do an operation in linux trying to burn cpu using openssl speed

this is my code from netflix simian army

#!/bin/bash
# Script for BurnCpu Chaos Monkey

cat << EOF > /tmp/infiniteburn.sh
#!/bin/bash
while true;
   do openssl speed;
done
EOF

# 32 parallel 100% CPU tasks should hit even the biggest EC2 instances
for i in {1..32}
do
  nohup /bin/bash /tmp/infiniteburn.sh &
done

so this is Netflix simian army code to do burn cpu, this executes properly but the issue is I cannot kill all 32 processes, I tried everything

pkill -f pid/process name
killall -9 pid/process name
etc.,

the only successful way I killed the process is through killing it via user

pkill -u username

How can I kill these process without using username?

any help is greatly appreciated

like image 735
Coding Ninja Avatar asked Mar 10 '23 17:03

Coding Ninja


1 Answers

finally, I found a solution to my own question,

kill -- -$(ps -o pgid= $PID | grep -o [0-9]*)

where PID is the process ID of any of the one processes running, this works fine but I am open to hear any other options available

source: http://fibrevillage.com/sysadmin/237-ways-to-kill-parent-and-child-processes-in-one-command

like image 50
Coding Ninja Avatar answered Mar 13 '23 06:03

Coding Ninja