LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Killing Child "su" process also kills parent (https://www.linuxquestions.org/questions/linux-general-1/killing-child-su-process-also-kills-parent-4175543797/)

pigsa 05-27-2015 10:19 PM

Killing Child "su" process also kills parent
 
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

pigsa 05-27-2015 11:19 PM

Resolved by upgrade coreutils to 8.4-37.el6 (CentOS 6.5 original version: 8.4-31.el6).

It is CentOS 6.5 instead of 6.6 :P


All times are GMT -5. The time now is 05:45 PM.