ExpertNoob
ExpertNoob

Reputation: 167

Control specific background subprocess in Bash script

"Parent" Bash script

bash Child &
wait
sleep 5; echo "Main end" >>log.txt

"Child" script :

trap 'echo "Child end" >>log.txt;' ABRT
sleep 100
echo "Child end" >>log.txt

Run: bash Parent &

How to modify these scripts so that "kill -ABRT" would make Child exit with a trace in log.txt ? As is, Child ignores such signals. It does if the first line (trap) is removed, but then, no trace is left in log.txt upon "kill -ABRT".

Upvotes: 1

Views: 194

Answers (1)

Piotr Zierhoffer
Piotr Zierhoffer

Reputation: 5139

I don't know if I get your question, but can't you operate on PID? You can get it/print it out from variable $!.

bash child1 &; echo $!;

And then just kill -ABRT that_pid.

Or do you want to kill a process running a specific child script?

Upvotes: 1

Related Questions