The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to make a parent wait on a child shells running in background? albertashish UNIX for Advanced & Expert Users 1 08-01-2008 10:13 AM
How to know the status of process running in background sumanta Shell Programming and Scripting 8 03-04-2008 02:03 AM
running process in background kingdbag UNIX for Dummies Questions & Answers 3 11-10-2006 09:34 AM
how to get background job to foreground sandilya Shell Programming and Scripting 4 02-02-2006 08:29 AM
set background/foreground color in .profile dvella UNIX for Dummies Questions & Answers 3 08-14-2005 04:12 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-28-2008
Registered User
 

Join Date: Nov 2007
Posts: 24
make a foreground running process to run background without hang up

I've tried this a long time ago and was successful but could not remember how i did it. Tried ctrl+Z and then used bg %

could not figure what i did after to keep it no hangup -

not sure if used nohup -p pid, can u plz help me out if this can be done.

Any help will be appreciated.
Reply With Quote
Forum Sponsor
  #2  
Old 08-28-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
To place a foreground process in the background: suspend the foreground process (with Ctrl-z) then enter the bg command to move the process into the background.

Show the status of all background and suspended jobs: jobs
Bring a job back into the foreground: fg %jobnumber
Bring a job back into the background: bg %jobnumber

Regards
Reply With Quote
  #3  
Old 08-28-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Depends on the shell whether bg jobs will receive a HUP when you log out; I believe with bash they will not.
Reply With Quote
  #4  
Old 08-28-2008
Registered User
 

Join Date: Nov 2007
Posts: 24
i'm working on a korn shell, but my script is running on bash mode, will it affect ?
Reply With Quote
  #5  
Old 08-29-2008
vertigo23's Avatar
Registered User
 

Join Date: Jul 2005
Location: SF, CA
Posts: 67
nohup

You can run your command with `nohup' - this will cause it to ignore all input and send its stdout (and stderr?) to the file "nohup.out" in your cwd. After you've run your command, you can background it as normal (^Z bg) but it will continue to run after you sever the terminal connection.

Depending on your shell (bash for sure, others maybe) you can also use the "disown" command on a job to disconnect it from the controlling terminal.
Reply With Quote
  #6  
Old 08-30-2008
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,262
When you have already started the job you can use "nohup <pid>" to unattach it from the terminal you are on (this is the reason why processes stop when you log off - they are attached to a terminal and this terminal ceases to exist when you log off) so they won't stop when you log off.

Therefore:

Code:
$ job                    # starts the job
$ <CTRL-Z>               # stops the job
$ bg                     # puts the job in background
$ nohup <PID>            # unattaches the backgrounded job from the terminal
I hope this helps.

bakunin
Reply With Quote
  #7  
Old 08-30-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
I had never heard of nohup PID and it does not seem to be supported by GNU coreutils nohup, so I guess it's not portable. But if it works for you, good.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
background, foreground, job control, nohup

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0