LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-27-2015, 10:19 PM   #1
pigsa
Member
 
Registered: Nov 2003
Location: Hong Kong
Posts: 35
Blog Entries: 1

Rep: Reputation: 15
Question 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

Last edited by pigsa; 05-27-2015 at 10:22 PM. Reason: Add OS info
 
Old 05-27-2015, 11:19 PM   #2
pigsa
Member
 
Registered: Nov 2003
Location: Hong Kong
Posts: 35

Original Poster
Blog Entries: 1

Rep: Reputation: 15
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
 
  


Reply

Tags
process, session, su


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
killng parent process without killing child process (Linux C programming) lettuce84@naver.com Linux - Newbie 3 07-24-2015 08:37 AM
[SOLVED] Killing subsequent child process upon parent receiving a signal acc_Wk Programming 19 07-14-2011 08:10 AM
Need solution to "failed to fork PTY" and "error creating the child process" problems Gnusboy Linux - Newbie 4 01-02-2010 07:54 AM
ns:"error when calling class OldSim"&tclsh:"invalid command+child process exits abn." shojaru Linux - Newbie 0 03-05-2009 04:23 AM
memory leak: Parent killing child process wkhoo Programming 12 06-04-2008 05:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration