Background process question

Hello,
I have a question, when i run some script in background for example:
Code:
./script &
This process should live till it ends or user (who run this script) decided to logoff, to avoid process kill when user exit sheel we use nohup. But it turns out that process put in background will survive without nohup command. I tried this on bash, ksh, sh and process is still working with ppid = 1. Can anyone explain it?
 
When shell quit it sends SIGHUP to all child processes and they should died i think (nohup makes process ignore SIGHUP signal). So suppose this behavior that i mentioned is normal what for is nohup command?
 
It can be for example
Code:
sleep 500 &
And it still run even when shell that exectute this command was killed. I repat my question what for is nohup when processes will survive.
 
Nowadays the hangup signal is rarely sent by anything other than a human using kill(1). The nohup command exists from the days of serial terminals where the UART driver in the tty(4) subsystem should send the userland process a SIGHUP if the line hangs up. When the shell receives a SIGHUP, it sends a SIGHUP to all its children too (you can test this manually), which kills them unless they're started with nohup or otherwise handle SIGHUP.

Shells can also send SIGHUP on normal exit, but I don't know of any that do this by default.
 
tmw said:
This process should live till it ends or user (who run this script) decided to logoff, to avoid process kill when user exit sheel we use nohup.
`we` its linux users? =) In freebsd this is normal action that process stays work
 
aragon said:
Nowadays the hangup signal is rarely sent by anything other than a human using kill(1).
Excuse me. SSH does, in fact, send a SIGHUP to the shell if the network connection dies, just like the UART driver does in the case of a serial terminal hanging up. So nohup may still be useful today, but I don't think it's ever been useful for leaving a process running after you explicitly and cleanly exit a shell. Shells only HUP their children in response to being HUP'd themselves.
 
Thanks for answers. So i can safely exit shell when i have processes in background with no risk. Im little confused because i read in "bash Cookbook: Solutions and Examples for bash Users" that nohup must be used when you have background process and leaves shell otherwise the background process will die.
 
To avoid this kind of problems I always start important processes in screen. Only then I know for sure the process won't be killed, unless the server reboots or screen dies ofcourse.
 
In bash there is an option "hugonexit", it is by defailt off in bash but when i turn this option on, background processes died when shell dies. I think in the past dying process in background when shell died was normal behavior but now this option is off by default in most shells.
 
Back
Top