1

"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".

2
  • Do you have control over your child scripts? Can you change their source? Commented Sep 6, 2013 at 11:53
  • Yes, I'm writing an execution manager that builds a main script and launches it, having it, and its children (exec units, who launch each thousands of subprossesses) trace their start/stop/exit codes (final subprossesses too) to a couple of log files, so that a report can be built afterwards showing the user how much of each exec unit is started/finished{with succes, failed}, .. by parsing those log files. Commented Sep 6, 2013 at 12:35

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, but how would child1 trap that signal ? If a trap is set in Main (so that it can trace its end too), child1 (with it's own trap) no longer gets that signal !! You can kill -ABRT pid_ch1 forever.. with no effect..
When a trap is set in Main, there is a strange "masking effect" that happens: it "closes children traps" who become unresponsive to signalling.. I couldn't get that under control.. I am actually asking if it's even possible to have separate control over Main/children.. Sending signals to Main (actually it's group process id) signals everybody which is not what I need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.