Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following processes.

ParentProcess
-- ChildProcess
-- ChildProcess
-- ChildProcess

How can I kill the parent process only? I want the children processes not to be killed. If I try to kill the parent process, the children will get SIGHUP and will get killed.

share|improve this question
5  
Is the definition of a child process that it is tied to it's parent? –  Brad Patton Mar 7 '13 at 16:30
    
umh, probably yes. It's tied to its parent. –  kcm1700 Mar 7 '13 at 17:17

1 Answer 1

Generally speaking, when a process becomes orphan (that is, its parent dies) it is adopted by init.

The special situation you describe probably applies to an interactive process when its controlling terminal closes (from Wikipedia):

The SIGHUP signal is sent to a process when its controlling terminal is closed. It was originally designed to notify the process of a serial line drop. In modern systems, this signal usually means that controlling pseudo or virtual terminal has been closed.

To prevent this, child processes should block SIGHUP, so in most cases you need cooperation from the parent process.

If the parent process is a shell (bash, csh and the like) and you want commands you run not to terminate when bash finishes, you can prefix any command with nohup (from info coreutils "nohup invocation"):

'nohup' runs the given COMMAND with hangup signals ignored, so that the command can continue running in the background after you log out.

In this example:

$ tty
/dev/ttys000
$ nohup find /dir -name file -exec rm {} \;

find won't be killed when the shell terminates and closes the controlling terminal /dev/ttys000.

If a shell script should block SIGHUP, use the builtin trap, as explained here for bash.

share|improve this answer
    
I have already opened process without nohup, any suggestions? –  kcm1700 Mar 7 '13 at 17:18
    
As far as I know you can't do much. Once processes run, you can't change the way they react to signals. –  jaume Mar 7 '13 at 17:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.