Operating System - Linux
1747988 Members
4899 Online
108756 Solutions
New Discussion юеВ

Re: will process die if started without nohup command after exiting terminal

 
Shivkumar
Super Advisor

will process die if started without nohup command after exiting terminal

Hi,

Generally, Software applications or tools running on Unix are being started by a startup script.
This startup script which starts the unix process usually uses nohup or if nohup is not provided we start the processes by appending nohup command exclusively before the process startup script.

My question:
If script do not have nohup command inside it and if someone start the process and logs out of the terminal; will the process die ?
Are running prcesses adopt shell process as their parent process if started without nohup command ?

Thanks,
Shiv
7 REPLIES 7
Wouter Jagers
Honored Contributor

Re: will process die if started without nohup command after exiting terminal

Usually the answer would be yes: when exiting your shell, a SIGHUP signal is sent to all child processes, which normally kills them. The nohup command makes a process ignore this SIGHUP signal (and the SIGQUIT signal).

Cheers,
Wout
an engineer's aim in a discussion is not to persuade, but to clarify.
Ralph Grothe
Honored Contributor

Re: will process die if started without nohup command after exiting terminal

It really depends how the process you start from an interactive shell is written.
If it was written like a daemon it usually would use a technique accordingly termed daemonization.
This means that it would fork and exit the parent process.
The fork provided an exact child copy.
It would also do a chdir to / (or some chroot if provided), close any from the parent inherited file descriptors or redirect them (at leeast the first three), and finally become session leader (e.g. setsid()) to totally dissociate from the shell it was started from.
So processes that do this kind of daemonization would not require a nohup.
Process that lack this behaviour are better started with a nohup (or maybe as a batch job).
Madness, thy name is system administration
Rasheed Tamton
Honored Contributor

Re: will process die if started without nohup command after exiting terminal

Hi,

The normal answer is yes.

In your case, if you are in doubt about it (deamons, etc) you can do a simple test.

Open two terminal sessions and just fireup your above script on the first one.

Do a ps on the processes started by script and note it.

Exit the terminal from you fired the script and check the processes from the second one.

You are done.

Regards,
Rasheed Tamton.
Daavid Turnbull
Frequent Advisor

Re: will process die if started without nohup command after exiting terminal

When using nohup I found that it did not work reliably unless the output was not directed to a location other than a tty device.

Eg:

nohup SomeCommand > /dev/null 2>&1 &

My assumption was that if the parent went away the child process had nowhere to send its output so it died anyway. (Somebody please correct me if this assumption is incorrect.)

Other flavours of Unix can behave differently.
Behold the turtle for he makes not progress unless he pokes his head out.
Dennis Handly
Acclaimed Contributor

Re: will process die if started without nohup command after exiting terminal

>When using nohup I found that it did not work reliably unless the output was not directed to a location other than a tty device.

Well, unless you are doing > /dev/tty, nohup(1) says it automatically redirects to nohup.out. And it also says if redirected to terminal, it sends to nohup.out. So it seems everything is covered.

>Other flavours of Unix can behave differently.

Unfortunately, that is probably true. :-(
Shivkumar
Super Advisor

Re: will process die if started without nohup command after exiting terminal

Are there more opinions from Unix Gurus ?

Thanks,
Shiv
TwoProc
Honored Contributor

Re: will process die if started without nohup command after exiting terminal

If the program does no terminal I/O and input and output streams are redirected, and it can get past possibly getting hit with a ctrl-c as you exit, some programs stay up fine, some don't - depending on how the program was written.
We are the people our parents warned us about --Jimmy Buffett