The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > SUN Solaris
.
google unix.com



SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
differnce between these cmds wrapster Shell Programming and Scripting 1 03-25-2008 11:49 AM
Using sudo for specific cmds scottsl UNIX for Advanced & Expert Users 3 12-07-2006 03:31 AM
difference between ksh and bsh tads98 Shell Programming and Scripting 4 08-10-2005 05:05 AM
difference rajashekaran UNIX for Advanced & Expert Users 1 04-23-2002 01:59 AM
?script/cmds 2 list open files???? bn80865 UNIX for Dummies Questions & Answers 3 01-22-2001 02:55 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-11-2004
billshu billshu is offline
Registered User
  
 

Join Date: May 2004
Posts: 3
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 (permalink)  
Old 05-11-2004
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
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 (permalink)  
Old 05-12-2004
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
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 (permalink)  
Old 05-12-2004
pressy's Avatar
pressy pressy is offline Forum Staff  
solaris cultist
  
 

Join Date: Aug 2003
Location: Vienna / Austria (Europe) [EARTH]
Posts: 726
......

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 (permalink)  
Old 05-12-2004
billshu billshu is offline
Registered User
  
 

Join Date: May 2004
Posts: 3
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 (permalink)  
Old 05-12-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0