LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 06-16-2010, 02:36 AM   #1
km_009
LQ Newbie
 
Registered: Jun 2010
Posts: 3

Rep: Reputation: 0
Unhappy Trying to bring back a disowned process to foreground


Hi

I had started a process through ssh and then i did 'cntrl+Z' and 'bg' and 'disown' before closing the ssh connection. That process kept running in the background in the other machine and now i want to bring it back to foreground in that machine. However running the command 'fg %<process_id>' is not helping. What do i DO!?
 
Old 06-16-2010, 02:49 AM   #2
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
Post

I dont think you have an option to bring a disowned process into foreground, because that is actually not running in your background.

Only, thing I know is you can grep its PID and know its status.
 
Old 06-16-2010, 04:49 AM   #3
km_009
LQ Newbie
 
Registered: Jun 2010
Posts: 3

Original Poster
Rep: Reputation: 0
That way i can only view its status, but in case i want to - say, input some data into a prompt or something for that process.. Then?
 
Old 06-16-2010, 08:39 AM   #4
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
Dear, running a job in background itself means you can not manually input data in it.

I dont think you there is way to bring that job to foreground to your terminal and give some input now.

I firmly think that you must automate all manual inputs before disown-ing a job.

Lastly, if you know the script name, try
Code:
ps -aef | grep "script name"
 
Old 06-16-2010, 08:58 AM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,541
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

You may want to look at using 'screen' first;

Quote:
excerpt from 'man screen';
NAME
screen - screen manager with VT100/ANSI terminal emulation

SYNOPSIS
screen [ -options ] [ cmd [ args ] ]
screen -r [[pid.]tty[.host]]
screen -r sessionowner/[[pid.]tty[.host]]

DESCRIPTION
Screen is a full-screen window manager that multiplexes a physical terminal between several processes
(typically interactive shells). Each virtual terminal provides the functions of a DEC VT100 terminal
and, in addition, several control functions from the ISO 6429 (ECMA 48, ANSI X3.64) and ISO 2022
standards (e.g. insert/delete line and support for multiple character sets). There is a scrollback
history buffer for each virtual terminal and a copy-and-paste mechanism that allows moving text
regions between windows.

When screen is called, it creates a single window with a shell in it (or the specified command) and
then gets out of your way so that you can use the program as you normally would. Then, at any time,
you can create new (full-screen) windows with other programs in them (including more shells), kill
existing windows, view a list of windows, turn output logging on and off, copy-and-paste text between
windows, view the scrollback history, switch between windows in whatever manner you wish, etc. All
windows run their programs completely independent of each other. Programs continue to run when their
window is currently not visible and even when the whole screen session is detached from the user's
terminal. When a program terminates, screen (per default) kills the window that contained it. If
this window was in the foreground, the display switches to the previous window; if none are left,
screen exits.
...
Just a few links to aid you to gaining some understanding;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Advanced Bash-Scripting Guide
Linux Home Networking


The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
1 members found this post helpful.
Old 06-16-2010, 09:14 AM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Yes, onebuck has the definitive solution to this problem. If only it could be used retro-actively....
--- rod.
 
Old 06-24-2010, 05:48 AM   #7
km_009
LQ Newbie
 
Registered: Jun 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks guys! It helped.
 
Old 04-18-2013, 03:01 AM   #8
Domination
LQ Newbie
 
Registered: Apr 2013
Posts: 2

Rep: Reputation: Disabled
Cool

I just created this account to put a reply to this thread. and Hello Linuxquestions!

I've herd about there is some programs that can ability to get back the running, and disowned processes to another terminal emulating window like putty window or another ssh window.
I think reptyr is one of them.
https://github.com/nelhage/reptyr

I'm interest about this. I tried but failed. really don't know how to use this program.
I googled, there were many tutorials but they didn't helped me to understand.

can some1 tell me some steps to get a running process back to the window via this programm?

ie.
Code:
top &
Code:
disown
retty pid (i dnt knw how to use it correctly)

screen is not the answer what um looking for.
because I don't wanna make another 1 more running process to do this.
Please help.

Last edited by Domination; 04-18-2013 at 03:04 AM.
 
Old 04-18-2013, 09:24 AM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
The problem is that the process never stays "disowned". All disowning a process does is give the process to pid 1.

So once you disown a process it then belongs to init - and you can't get it back for any reason.

stdin/stdout/stderr are disconnected from the controlling terminal (the act of disowning it) unless they have been redirected to/from a file. Once disconnected, the data stream is closed...

What "screen" does is create a socket for communications with the screen server... which may be disconnected. The socket remains for "screen" (operating as a client) can connect to. Any processes started by screen remain attached to the pseudo terminal(s) allocated for use as a terminal. The screen utility (server side) then manages those terminal sessions.
 
1 members found this post helpful.
Old 04-18-2013, 09:30 AM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
If you don't 'disown', you can bring it back with 'fg' by passing the job no eg
Code:
# run top in background
top &
[1] 20310

# recall job num 1 to foreground
fg 1
top

top - 23:29:02 up 10:06,  5 users,  load average: 0.03, 0.05, 0.00
Tasks: 167 total,   1 running, 166 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.5%us,  0.9%sy,  0.0%ni, 96.3%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   7801324k total,  1330500k used,  6470824k free,    70472k buffers
Swap:  3897336k total,        0k used,  3897336k free,   526100k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND             
20310 chris     20   0 15028 1132  816 R  3.6  0.0   0:00.07 top
 
  


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
how can i bring the backgroud process to foreground ZAMO Linux - Enterprise 10 03-05-2012 10:35 AM
To bring a window in the foreground dale_chip Programming 3 04-05-2008 08:30 PM
background process popping up in foreground noir911 Linux - General 1 12-15-2007 12:53 AM
How to bring a background diamon to foreground lieuquocdat Linux - Software 8 07-20-2006 07:53 AM
How to know the foreground process group ID of another console ?? sreeramabsc Linux - General 0 01-30-2006 02:26 AM


All times are GMT -5. The time now is 06:31 PM.

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