LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices

Reply
 
Search this Thread
Old 12-19-2007, 12:54 AM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 579

Rep: Reputation: 30
Thumbs up how can i bring the backgroud process to foreground


Hi,

I had started a script, which i want to run it in the background . It started suceessfully . Now i want to bring that same process to foregroud. How can i do it?


I used the following command to start it , as a background process.
nohup ./script&

Please Advise
 
Old 12-19-2007, 01:28 AM   #2
utcursch
LQ Newbie
 
Registered: Nov 2004
Distribution: Ubuntu
Posts: 12

Rep: Reputation: 0
Code:
fg
fg %1 will bring a job 1 from the background into the foreground. fg %1 & will resume job 1 in the background.
 
Old 12-19-2007, 01:49 AM   #3
KrahnacK
Member
 
Registered: Nov 2007
Location: /dev/volcano
Posts: 70

Rep: Reputation: 15
if you don't need it, you should remove the nohup from your script, because it acts like a disown for the shell, and you won't be able to put the job in foreground if you don't own it...

to see the processes your current shell owns, just type "jobs", then to put in foreground a job it is as utcursh says : "fg %job_id"

in your case i advice you to just do a "./script&" unless you want the script to continue running after you closed your shell.
 
Old 12-19-2007, 01:57 AM   #4
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 579

Original Poster
Rep: Reputation: 30
Thank you both.

I want the script to continue running after i closed my shell.

"you should remove the nohup from your script, because it acts like a disown for the shell, and you won't be able to put the job in foreground if you don't own it... "

Then How can i start a script to run in background,(to be owned) and want to continue running after i closed my shell.
 
Old 12-19-2007, 03:53 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,352

Rep: Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041
"man screen"
 
Old 12-19-2007, 04:30 AM   #6
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 579

Original Poster
Rep: Reputation: 30
Thank you,
Yes , am used to screen and its usage in the past. Here , i need to know How can i start a script to run in background,(to be owned) and want to continue running after i closed my shell.
 
Old 12-19-2007, 08:38 AM   #7
KrahnacK
Member
 
Registered: Nov 2007
Location: /dev/volcano
Posts: 70

Rep: Reputation: 15
actually, i don't know how to do, since when you run a script (owned by your shell), can be in background ot not, it will receive a SIGHUP signal when you close your shell (which default action is to terminate the script).

The nohup app is there to make the shell to "disown" the script so that it won't receive this signal at shell termination. The fact that your script isn't owned by your shell doesn't allow your shell to consider it as a shell job, and so i don't think it is possible to put it in foreground of the shell...

the only walkthrough i see is to make your script handle the SIGHUP signal (by registering an appropriate handler, see "man signal" or "man sigaction" for more info), in order to make sure it won't quit after shell termination. In this situation you won't need the nohup application and so your script will still be owned by your shell, so you will be able to put it in foreground.

However, note that this is only true until your shell is alive (i don't know if it is possible to make a new shell re-own a script that was own by another shell...) : your script will still run after you close your shell, but it won't be sufficient to put it in foreground in another shell...

i hope this is understandable, cause i don't think my post is -_-'
so if you need explanations, don't hesitate!
 
Old 12-19-2007, 09:43 AM   #8
farslayer
Guru
 
Registered: Oct 2005
Location: Willoughby, Ohio
Distribution: linuxdebian
Posts: 7,228
Blog Entries: 5

Rep: Reputation: 189Reputation: 189
I thought the Screen response was pretty good.

Connect with your shell
Start screen
Launch your script in the screen session and then disconnect your shell..

when you reconnect, you can re-attach to the screen session and access the running script..

what part of using screen are you saying is no good or won't work ?
 
Old 12-24-2007, 12:24 AM   #9
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 579

Original Poster
Rep: Reputation: 30
yes,

Finally i decided to use screen as it is familiar to me.
 
Old 02-27-2012, 04:17 AM   #10
taepodong1101
LQ Newbie
 
Registered: Feb 2012
Posts: 2

Rep: Reputation: Disabled
for search engines

You can also use tail -f to bring it back to foreground.

So,

To put a running process to background you run:

$ nohup command &

for example,
$ nohup ping 127.0.0.1 &

To bring it back to foreground you run

tail -f nohup.out
 
Old 03-05-2012, 09:35 AM   #11
houninym
LQ Newbie
 
Registered: Apr 2010
Location: UK
Distribution: (K/X/ )Ubuntu, RHEL, Fedora, SLES
Posts: 4

Rep: Reputation: 1
Exclamation

Hi Taepodong,

No, tail -f is not putting the job back into foreground. The tail -f is just creating a pipe that is copying the output of nohup.out onto your screen as it is written. The process is still disowned, you can't respond to prompts the process attempts to make to it's terminal.

So even if it wants a password you can't provide one.
 
  


Reply

Tags
background, process


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
background process popping up in foreground noir911 Linux - General 1 12-14-2007 11:53 PM
Bash child process in foreground while parent dies kborgnis Programming 3 11-09-2007 06:50 AM
how do i bring up a running process? szandor Linux - General 2 02-28-2007 04:14 AM
How to bring a background diamon to foreground lieuquocdat Linux - Software 8 07-20-2006 06:53 AM
How to know the foreground process group ID of another console ?? sreeramabsc Linux - General 0 01-30-2006 01:26 AM


All times are GMT -5. The time now is 11:43 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration