Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 267
Source Link
user
  • 31
  • 1
  • 2

Kill a running shell script, and kill all process running within it

I have a shell script running in the background, which runs 5 different jobs.

When I run the shell script all 5 jobs start running in order. When I kill this shell, whichever process is running, will still continue to run, even though I have killed the shell.

$ bash shell.sh & echo $!

this gives me the PID of the shell, which allows me to kill it later if I wish to do so at some point.

#!/bin/bash

JOB1
JOB2
JOB3
JOB4
JOB5

How can I make the shell kill all process running within, once it has been killed?