What's the difference: 'nuhup cmds' Vs 'cmds &'


 
Thread Tools Search this Thread
Operating Systems Solaris What's the difference: 'nuhup cmds' Vs 'cmds &'
# 1  
Old 05-11-2004
What's the difference: 'nuhup cmds' Vs 'cmds &'

Hello,

Case: If I want to run a script background and logout, which command should I use ?

1)# ./script_name &
2)# nohup script_name
3)# nohup script_name &

And any differences ?

What happens if I redirect the output to a file?

I learned somewhere that the (1) format will stop after you logout, because the kernel sends SIGHUP to all of your processes after the Shell exits. But my experence told me that the script keep running after I logout.

So, I am confused here:

Could someone giudes me out...
Thanks,
# 2  
Old 05-11-2004
I may be very wrong here, but I think the best route would be to use #3.

The first may work if the process you're running does not exit on SIGHUP. Some, such as inetd, simply reread their config and keep processing. Some of the scripts I write ignore SIGHUP purposely.

The second will trap SIGHUP, but not place it in the background right away. I believe it will is you press "susp", Control-Z in my case.

The last will trap SIGHUP, and run the job in the background.

Again, these may not be correct, since I'm working from memory here.
# 3  
Old 05-12-2004
If you don't redirect the output to a file it will go to a file called nohup.out.

Otherwise, output goes where you specify.

Do a "man nohup" for more info.
# 4  
Old 05-12-2004
......

3)# nohup script_name &

thats the right one....

nohup = the process is the child of the id 1
script_name = starts the script
& = starts the script in backround, otherwise you could not exit your terminal....

greetings pressy
# 5  
Old 05-12-2004
Thanks for reply.

Yes, I knew the "script_name &" can put it background and I can logout, then check it next time login. Suppose the script doesn't trap any signal, or exit on signal, just an infinite loop and sleep, my confusion is if "script_name & " can have the job done, why prefer to use 'nohup'? What's benificial of using 'nohup'?

"man nohup" says it immune to SIGHUP. From user's point of view, if I don't trap or exit on SIGHUP, is there any reason that I must or better use "nohup" to start the script?
# 6  
Old 05-13-2004
The default action for HUP is to exit. If you don't defeat that somehow, your script will exit when it gets a HUP. nohup is one way. And scripts can ignore HUP if they want to. If a script is explicitly ignoring HUP, nohup is not also needed. But some people will use nohup rather than checking the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Difference between lsconf & prtconf cmds on AIX

Friends, Could someone answer me on a silly question of mine: What's the difference between lsconf & prtconf commands of AIX? I find the o/p's of either of these commands to be same. Excuse me if I'm missing something, also I google-ed about it before turning down here for answer. ... (3 Replies)
Discussion started by: thisissouvik
3 Replies

2. Shell Programming and Scripting

Perl cmds doesn't work in Bash shell . Plz help

Hi everyone, I have a Linux OS in my PC (older version 9). Its default shell is bash. Whenever I try to run some Perl program it throws error ! eg, if I run this simple PERL program , #!/usr/bin/perl printf "\lHello \n"; $var=3 ; printf $var; @list=(1,2,3); printf "@list";... (6 Replies)
Discussion started by: adc22
6 Replies

3. UNIX for Dummies Questions & Answers

Running cmds from a file

I specified in my file that all cmds are bash: ------------ #!/bin/bash ls -l ------------ thats the file how would i run that one command? (2 Replies)
Discussion started by: oxoxo
2 Replies

4. Shell Programming and Scripting

How to run cmds after changing to a new env (shell) in a shell script

Hi, I am using HP-UNIX. I have a requirement as below I have to change env twice like: cadenv <env> cadenv <env> ccm start -d /dbpath ccm tar -xvf *.tar ccm rcv .... mv *.tar BACKUP but after I do the first cadenv <env> , I am unable to execute any of the later commands . ... (6 Replies)
Discussion started by: charlei
6 Replies

5. UNIX for Dummies Questions & Answers

Errors while executing mysql cmds in SUn solaris server

Hi All, I am using mysql at sun solaris unix(Hp) server. I logged into mysql server with root as user. its logged in properly. Then i used 'show databases' mysql command. its display all the available databases. for example mysql > show databases; It displayed as follows. exampledb1... (1 Reply)
Discussion started by: dbsurf
1 Replies

6. Shell Programming and Scripting

Errors while executing cmds in sun solaris

Hi All, I am using mysql at sun solaris unix(Hp) server. I logged into mysql server with root as user. its logged in properly. Then i used 'show databases' mysql command. its display all the available databases. for example mysql > show databases; It displayed as follows. exampledb1 ... (1 Reply)
Discussion started by: dbsurf
1 Replies

7. Shell Programming and Scripting

differnce between these cmds

Hi all, I would like to know the difference between these commands /usr/lib/fs/hsfs/mount -F /dev/lofi/1 /usr and mount -F hsfs /dev/lofi/1 /usr In the first case absolute path is specified and in the next the cmd with options ,whats the differnce. PS:am sorry ,coz this had been... (1 Reply)
Discussion started by: wrapster
1 Replies

8. UNIX for Advanced & Expert Users

Using sudo for specific cmds

I've been asked to provide access to my system for another group of individuals to perform WebSphere and Portal tasks (stop/start specifically). I run both as root (we can debate this one later) and so know I have to figure out a way for these individuals to start and stop WebSphere and Portal as... (3 Replies)
Discussion started by: scottsl
3 Replies

9. UNIX Desktop Questions & Answers

what is the difference between Unix & linux, what are the advantages & disadvantages

ehe may i know what are the difference between Unix & Linux, and what are the advantages of having Unix as well as disadvantages of having Unix or if u dun mind i am dumb do pls tell me what are the advantages as well as the disadvantages of having linux as well. thanks (1 Reply)
Discussion started by: cybertechmkteo
1 Replies

10. UNIX for Dummies Questions & Answers

?script/cmds 2 list open files????

I would like to have the commands or a scripts that will show me files that are not open by any process and meet a certain pattern (ie arch.log1_117512.dbf). Basically I a wanting to delete all arched redo logs that oracle has popped out execpt for the current one it is writting to. I am... (3 Replies)
Discussion started by: bn80865
3 Replies
Login or Register to Ask a Question