nohup and background process | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

nohup and background process

UNIX for Advanced & Expert Users


Tags
nohup

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-04-2007
srksn srksn is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 13 September 2007, 2:26 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
nohup and background process

What is the difference between running a process using nohup and running a process in background ? Please explain
Sponsored Links
    #2  
Old 09-04-2007
shahnazurs shahnazurs is offline
Registered User
 
Join Date: Jul 2005
Last Activity: 10 October 2011, 11:03 AM EDT
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #3  
Old 09-04-2007
srksn srksn is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 13 September 2007, 2:26 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
difference between nohup and &

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
    #4  
Old 09-04-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Advisor  
Full Time Dad
 
Join Date: Sep 2006
Last Activity: 4 April 2014, 3:58 AM EDT
Location: Rossem, Tazenda
Posts: 1,211
Thanks: 6
Thanked 18 Times in 17 Posts
Quote:
Originally Posted by srksn View Post
By nohup you say no hangup, what do you mean by no hangup? Please explain more
From the documentation of nohup:
Code:
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.


Code:
`nohup' does not automatically put the command it runs in the background;
you must do that explicitly, by ending the command line with an `&'.

Sponsored Links
    #5  
Old 09-04-2007
porter porter is offline Forum Advisor  
Registered User
 
Join Date: Jan 2007
Last Activity: 8 January 2008, 6:50 PM EST
Posts: 2,965
Thanks: 0
Thanked 5 Times in 5 Posts
Quote:
Originally Posted by srksn View Post
By nohup you say no hangup, what do you mean by no hangup? Please explain more.
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.
Sponsored Links
    #6  
Old 01-22-2009
kukuruku kukuruku is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 5 May 2009, 3:31 AM EDT
Location: Moscow, Russia
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
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 & ?
Sponsored Links
    #7  
Old 01-27-2009
adderek adderek is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 12 August 2010, 12:56 PM EDT
Location: Poland
Posts: 123
Thanks: 2
Thanked 3 Times in 3 Posts
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
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Background (nohup * &) SSH command block possible? doonan_79 Programming 4 04-27-2012 08:45 AM
how do i execute nohup and background job inside the korn script for db2 Hangman2 Shell Programming and Scripting 3 02-28-2012 08:37 PM
How to run background(child) process in PHP without blocking the usual flow of parent process on Lin elizas Linux 1 02-03-2010 06:13 PM
Why the nohup-ed background process always is "stopped" ? meili100 Shell Programming and Scripting 4 06-02-2009 06:02 PM
Why the nohup-ed background process always is "stopped" ? meili100 UNIX for Advanced & Expert Users 1 05-27-2009 05:27 AM



All times are GMT -4. The time now is 06:56 AM.