1
1
I have a script from which I run a second script in a subshell. What's the soonest that can send a signal to the second script?
script1:
./script2 &
kill -SIGCONT $!
script2:
echo "~~ ENTRY"
trap 'SUSPEND=false' SIGCONT
SUSPEND=true
while $SUSPEND; do; sleep 1; done
echo "~~ EXIT"
This won't work, the terminal will just hang there in "suspended" mode. My guess is that because I call kill
straight away after I run script2, the trap in script2 doesn't have time to get parsed, and thus nothing happens - race condition.
So what's the soonest I can send the signal to the child process - making sure that it gets trapped?
There's no way to predict. Theoretically, if the system is busy enough with high-priority processes,
script2
might NEVER get to thetrap
command. – Barmar – 2014-08-29T18:24:17.243What you could do is have
script2
do something like write into a file after it traps the signal.script1
could loop, checking for a modification of the file. – Barmar – 2014-08-29T18:25:53.447