LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-05-2011, 03:14 PM   #1
siasia
LQ Newbie
 
Registered: Apr 2011
Posts: 5

Rep: Reputation: 0
Bringing back to foreground a process whose terminal is killed


I have started a new process in a terminal in the background (i.e. using &) and have closed that terminal. My program is still running but I cannot look at its standard error. Is there a way to bring that process back to the foreground in a different terminal? (or is there otherwise a way to look at its standard error now that its terminal close?)
Note that I don't want to terminate and re-run the process.

I have a feeling it's not possible but thought maybe someone has an idea?
 
Old 04-05-2011, 03:18 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,133
Blog Entries: 2

Rep: Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836
If you use & to run a program in background the program will be killed together with the terminal, so there is no way to get that program back to the foreground.
 
Old 04-05-2011, 03:25 PM   #3
siasia
LQ Newbie
 
Registered: Apr 2011
Posts: 5

Original Poster
Rep: Reputation: 0
thanks for the quick reply!

hmm, I don't think it's killed. I do see it when I run top.
 
Old 04-05-2011, 04:01 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,133
Blog Entries: 2

Rep: Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836
I just tried it with two different programs, kate and gvim. While kate is killed with closing the terminal, surprisingly gvim is not.
After a short research I found out that gvim seems to detach itself from the terminal. When I start it as background process, the shell notifies me with its process ID:
Code:
tobi@monster ~ :) % gvim &
[1] 6629
In this case the process ID is 6629. If I now grep for gvim in a ps output I come to this:
Code:
[1]  + done       gvim                                                          
tobi@monster ~ :) % ps aux | grep gvim
tobi      6632  0.0  0.1 160048 12652 ?        SNs  22:57   0:00 gvim
tobi      6638  0.0  0.0   4816  1048 pts/0    S+   22:59   0:00 grep --color=auto gvim
So gvim seems to start another process (PID 6632) and ends the starting process (PID 6629).

Sadly, I have no clue how to get that to the foreground if it is not a GUI application.
 
Old 04-05-2011, 05:54 PM   #5
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
I think you need to learn about screen, because it will let you detach from and then reattach to processes/programs.

It'll solve your problems for the future, but maybe not your current one.
 
Old 04-05-2011, 06:41 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
Conventionally, '&' puts a program in the background, but leaves it connected to the initiating terminal, so it dies when the terminal session goes away.
To disconnect it from the terminal at startup, prefix with 'nohup' thus
Code:
nohup ./myprog >myprog.log 2>&1 &
The prog in qn may or may not initiate an associated process that is disconnected from the terminal and does not go away when the terminal does.

As per tredegar, another option is to use the screen cmd, but as with nohup, this must be done at the startup time, not post-facto.
 
  


Reply


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
[SOLVED] Trying to bring back a disowned process to foreground km_009 Linux - Newbie 9 04-18-2013 08:30 AM
scheduling process in the foreground? deathmaggot Linux - Newbie 6 12-09-2010 01:12 AM
how to move background process to foreground batola Linux - Server 29 03-10-2010 10:28 AM
[SOLVED] [bash]Pick up process running in back up by another terminal... RaptorX Linux - General 5 09-02-2009 01:29 PM
background process popping up in foreground noir911 Linux - General 1 12-14-2007 11:53 PM


All times are GMT -5. The time now is 10:23 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration