Results 1 to 7 of 7
Thread: how to detach a running process?
|
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
03-27-2005 #1Linux Newbie
- Join Date
- Oct 2004
- Posts
- 139
how to detach a running process?
Is there a way to detach a currently-running process from the curent tty?
-
03-29-2005 #2Just Joined!
- Join Date
- Mar 2005
- Location
- Milano (Italy)
- Posts
- 45
you have to use the command screen
-
03-29-2005 #3Linux Newbie
- Join Date
- Oct 2004
- Posts
- 139
switch to the terminal of where the command was launched from and type:
Originally Posted by debian_user
or justCode:[CTRL-Z] bg [number]
, if you only launched one command from the current terminalCode:bg
-
04-01-2005 #4Just Joined!
- Join Date
- Mar 2005
- Location
- Northern Ireland
- Posts
- 23
Further info : after running bg command to background the process you can then get a list of backgrounded jobs by typing
; and the status of each job (running, stopped, etc) For exampleCode:jobs
To bring a process back to the foreground, use fg command; contuning the example:Code:[dtodd@localhost dtodd]$ sleep 120 <CTRL-Z here> [1]+ Stopped sleep 120 [dtodd@localhost dtodd]$ bg [1]+ sleep 120 & [dtodd@localhost dtodd]$ jobs [1]+ Running sleep 120 & [dtodd@localhost dtodd]$
To kill a job in the background, get the job number and kill %<number>, ie, sleep jobs was number 1; so:Code:[dtodd@localhost dtodd]$ fg sleep 120
All good stuff - I hope it's usefulCode:[dtodd@localhost dtodd]$ jobs [1]+ Running sleep 120 & [dtodd@localhost dtodd]$ kill %1 [dtodd@localhost dtodd]$ [1]+ Terminated sleep 120 [dtodd@localhost dtodd]$
-
04-01-2005 #5either this or put an & at the end of the application. eg.
Originally Posted by debian_user
will run ntop in the background.Code:ntop &
Screen is more for applications where you want to see any output generated, but also want to background the process."I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327
-
04-01-2005 #6Linux Newbie
- Join Date
- Oct 2004
- Posts
- 139
I thought "debian_user" meant the "command prompt", because I don't have the "screen" utility installed.
Originally Posted by sdousley
-
11-21-2008 #7Just Joined!
- Join Date
- Nov 2008
- Posts
- 2
screen, disown
I'm afraid none of the commands given so far, useful as they may be, actually detach a process from a tty. ^Z suspends a job, bg backgrounds it, and fg foregrounds it, but it's still attached. It can still print messages, and it will still be sent a termination signal if you disconnect the tty (close the window if you're using a graphical shell.)
If you truly wish to detach a process, there are two ways to do it. The first is to use "screen." The advantage to this method is that screen essentially creates a second layer between the tty and the programs running inside of it, so you can detach and reattach at will, and without messing up the output or otherwise causing yourself headaches. You can even detach on one tty and reattach on a different one. Or several different ones.
The problem with screen, of course, is that you have to start it *before* you start the process you will later wish to detach. If, by some mistake, you didn't do that, you're not completely out of luck. The other command you can use is "disown" This completely detaches the job from the tty. You can logout/close the window and the job will continue merrily along its way in the background. (be sure you bg it before you disown it. I'm not sure all systems would necessarily unsuspend it when you issue the disown command.
The big disadvantage to disown is that it is exceedingly difficult, if not impossible to reattach the process to your tty if you decide you want it back. So use it with caution.


