LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Enterprise (http://www.linuxquestions.org/questions/linux-enterprise-47/)
-   -   how can i bring the backgroud process to foreground (http://www.linuxquestions.org/questions/linux-enterprise-47/how-can-i-bring-the-backgroud-process-to-foreground-607782/)

ZAMO 12-19-2007 01:54 AM

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

utcursch 12-19-2007 02:28 AM

Code:

fg
fg %1 will bring a job 1 from the background into the foreground. fg %1 & will resume job 1 in the background.

KrahnacK 12-19-2007 02:49 AM

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.

ZAMO 12-19-2007 02:57 AM

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.

syg00 12-19-2007 04:53 AM

"man screen"

ZAMO 12-19-2007 05:30 AM

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.

KrahnacK 12-19-2007 09:38 AM

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!

farslayer 12-19-2007 10:43 AM

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 ?

ZAMO 12-24-2007 01:24 AM

yes,

Finally i decided to use screen as it is familiar to me.

taepodong1101 02-27-2012 05:17 AM

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

houninym 03-05-2012 10:35 AM

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.


All times are GMT -5. The time now is 05:04 AM.