0

If I run ./script.sh &, where script is the following:

#!/bin/bash
echo "hello"
sleep 30
echo "hello again"
sleep 30
touch /root/foo.txt

Then I use ps au, to identify the "sleep" call process id, which I subsequently terminate, via kill -HUP . The program then finishes still. Will the child "sleep" notify its parent?

However, if I run echo "hello" && sleep 30 && echo "hello again" && sleep 30 && touch /root/testFILE.txt &, and repeat the process, the program does not finish. Why is this? It does in fact "touch" the file, if, during the last "sleep", I disconnect (as I am connected via ssh to an ec2 instance, running amazon linux 2, over ssh).

The disconnect should send a HUP signal to the sleep command (I think), which should have the same results as in the above paragraph but, lo and behold, upon my return the file is there....

(note: if I manually, via kill -HUP , send the the hup signal during this last "sleep", the file isn't created either...) What is going on? Is there any chance it is related to it being an ec2 instance or is this solely explainable by the unix os?

0

1 Answer 1

0

The script will run all commands no matter what. With your command line, you are using & not ; so each command will run only if the previous one was successful. A killed sleep is not successful, or if you like doesn't have a return value of 0 (success!) but 129 which is not success.

Incidentally, the value 129 is the signal number (HUP is 1) plus 128, if you used SIGTERM which is signal 15 it's 143. Either way, 129 or 143 is not 0 so the next command in your string of commands won't run.

Not the answer you're looking for? Browse other questions tagged .