What is the difference between running a process using nohup and running a process in background ? Please explain
Hi,
nohup - no hangup
when you suffix with & for running some task, this task will run in background.
example
cat ex.txt|sort &
if you want to continue this job after you log out from your terminal, you can prefix with nohup
nohup cat ex.txt|nohup sort &
Thanks,
Shahnaz.
what is the difference between nohup and & say
1)nohup cat test.dat
and
2)cat test.dat &
and
3) nohup cat test.dat &
By nohup you say no hangup, what do you mean by no hangup? Please explain more
Thanks
From the documentation of nohup:
Run a command immune to hangups, runs the given COMMAND with hangup signals ignored,
so that the command can continue running in the background after you log out.
`nohup' does not automatically put the command it runs in the background;
you must do that explicitly, by ending the command line with an `&'.
When you run a command from an interactive shell you have a "controlling terminal" managed by sshd, telnetd, xterm or whatever.
Then that controlling terminal closes it sends the processes under it's umbrella a 'SIGHUP' signal, this will normally kill those processes. 'nohup' traps this signal and may detach from the controlling terminal.
Hi.
I restore this thread because i have question on the same theme.
I read that when running command in background with &, after logout it must terminate.
But i often run commands like "bzip .. &", then logout - and they don't terminate and continue to work as many time as they have to.
I want understand why?
Because, i think, i can use this ability in scripts some time and it won't work. May be i have to use nohup instead of & ?
Running in the background (with & at the end) = spawning a child process that has current process as its parent. If you disconnect from the current shell (=hangup the parent) then you hangup the child as well.
If the child can handle this hang-up in some way - it could be possible to disconnect.
Usually you should not be able to disconnect while having any background/foreground jobs.
nohup runs a process that is somewhat separated from the current process (terminal). It is executed in a "deeper background". Thus you should be able to logout after starting such a process.
See "screen" - a very nice application