nohup and background process


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users nohup and background process
# 1  
Old 09-04-2007
nohup and background process

What is the difference between running a process using nohup and running a process in background ? Please explain
# 2  
Old 09-04-2007
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.
# 3  
Old 09-04-2007
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
Quote:
Originally Posted by srksn
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 `&'.

# 5  
Old 09-04-2007
Quote:
Originally Posted by srksn
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.
# 6  
Old 01-22-2009
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 & ?
# 7  
Old 01-27-2009
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 Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make background process interact with fg process

Hi, I have written a menu driven shell script in which as per the choice, I run the another script on background. For eg: 1. get info 2)process info 3)modify info All the operations have different scripts which i schedule in background using &. However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies

2. UNIX for Dummies Questions & Answers

How do I send output of a background process to a file other than nohup.out?

I have a question. I will be running a background process using nohup and & command at end. I want to send output to a file say myprocess.out. So will this command work? nohup myprocess.ksh > myprocess.out & Thanks in advance guys !!! :) (3 Replies)
Discussion started by: vx04
3 Replies

3. Shell Programming and Scripting

Nohup and background jobs

Hi All, Can someone help me in knowing the exact difference between nohup and &. The definition is quite clear but i only want to know if i run my job using & and in between i hung up my terminal. (10 Replies)
Discussion started by: Uinx_addic
10 Replies

4. Shell Programming and Scripting

How to stop nohup which is working background

Please I have run a background script using nohup please tell me way to stop this. Thanks in Advance (4 Replies)
Discussion started by: mumakhij
4 Replies

5. Programming

Background (nohup * &) SSH command block possible?

Hello, I am trying to find a way to send several sequential commands via SSH to a remote box in a single command. Thoughts so far: 1) Can I put them into a function and call the function within the ssh command? e.g. ssh <targetserver> $(functionx) No - then it calls the function in... (4 Replies)
Discussion started by: doonan_79
4 Replies

6. Shell Programming and Scripting

how do i execute nohup and background job inside the korn script for db2

load_cursor_stmt() { ls /db/admin/ddl/rmn01000/load_cursor*.sql|while read file do echo "${file}" `nohup db2 -tvf "$file" \&` done }Error: ------- /admin/ddl/rmn01000/load_cursor5.sql /db/admin/ddl/rmn01000/load_cursor6.sql + read file + echo... (3 Replies)
Discussion started by: Hangman2
3 Replies

7. Shell Programming and Scripting

How to put FTP process as a background process/job in perl?

Hi, I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming. So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies

8. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

9. Shell Programming and Scripting

Why the nohup-ed background process always is "stopped" ?

I let a script A call script B. I used nohup a.sh &>/tmp/log & In script A it calls B directly, without any redirecting or nohup or background. However A is always "Stopped", while B is running correctly. Anybody knows why? thanks! -----Post Update----- BTW, if I don't use nohup... (4 Replies)
Discussion started by: meili100
4 Replies

10. UNIX for Advanced & Expert Users

Why the nohup-ed background process always is "stopped" ?

I let a script A call script B. I used nohup a.sh &>/tmp/log & In script A it calls B directly, without any redirecting or nohup or background. However A is always "Stopped", while B is running correctly. Anybody knows why? thanks! -----Post Update----- BTW, if I don't use nohup... (1 Reply)
Discussion started by: meili100
1 Replies
Login or Register to Ask a Question