CentOS 6.6
I have a simple script parent.sh
Code:
#!/bin/bash
echo "Sleeping ZZZzzz..."
su $USER -c "sleep 500"
#sleep 500
echo "Waked up"
When the script was running (and sleeping), if the su command was killed, parent.sh is also killed, such that the "Waked up" message was not displayed. Why killing a child affect the parent?
Sample transcript:
On session 1 (parent.sh running and sleeping):
Code:
[root@mylinux ~]# ./parent.sh
Sleeping ZZZzzz...
On session 2:
Code:
[root@mylinux ~]# ps -ef|grep sleep
root 6779 6778 0 10:56 pts/1 00:00:00 su root -c sleep 500
root 6783 6779 0 10:56 pts/1 00:00:00 sleep 500
root 6785 24265 0 10:56 pts/2 00:00:00 grep sleep
[root@mylinux ~]# kill 6779
In session 1, parent.sh is also killed. Complete message:
Code:
[root@mylinux ~]# ./parent.sh
Sleeping ZZZzzz...
Session terminated, killing shell... ...killed.
Terminated
[root@mylinux ~]#
Note:
1. if sleep is not run with su (i.e., use the commented out sleep), or I kill the actual sleep command instead of su command (6783 in above sample), parent.sh is not killed.
2. I forgot what I did, but in attempts to pinpoint the issue, I got message like "terminated 143", where exit code 143 probably means program killed by SIGTERM