Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following processes.

-- 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
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

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
$ 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
How do I put an already-running process under nohup?… – PeterVermont Nov 10 '15 at 20:12

You must log in to answer this question.

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