Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a running program on a SSH shell. I want to pause it and be able to unpause its execution when I come back.

One way I thought of doing that was to transfer its ownership to a screen shell, thus keeping it running in there.

Is there a different way to proceed?

share|improve this question
See also Can I nohup/screen an already-started process? and Resume command running in dropped SSH session, which mention several ptrace-based solutions not (currently) mentioned here. – Gilles Nov 15 '10 at 22:47
From questions like unix.stackexchange.com/a/4039/13496 I'm hearing about retty and neercs. Hmmm... wonder if there's smth like a "screen here" layer before I run a process next time should I lose the top terminal in the future, that will make it easy to snap back in the stdin/out/err – Marcos Mar 8 '12 at 15:00
The secondary/implicit issue in this question I can't fathom is...why did the shell choose to disown a suspended job when there is a newer/just launched one in background that doesn't even need/wait for stdin? This is the treatment I've gotten used to so don't know what went different here... – Marcos Mar 11 '12 at 13:54
up vote 67 down vote accepted

Using GNU screen is your best bet.

Start screen running when you first login - I run screen -D -R, run your command, and either disconnect or suspend it with CTRL-Z and then disconnect from screen by pressing CTRL-A then D.

When you login to the machine again, reconnect by running screen -D -R. You will be in the same shell as before. You can run jobs to see the suspended process if you did so, and run %1 (or the respective job #) to foreground it again.

share|improve this answer
Wow, I can't believe an answer of GNU Screen is currently the lowest rated. Am I missing something? – Faheem Mitha Mar 21 '11 at 5:55
Perhaps! Seems like the best to me. – Andrew Yochum Mar 21 '11 at 16:35
Looking back, it clearly appears to be the most painless solution, provided you can plan accordingly and launch your processes from within a screen environment. Anyways, I made it the official answer! – levesque Jul 8 '12 at 0:48
I think this doesn't answer the question. The question begins with "I have a program running". This answer assumes it's not running yet… – Anko Apr 16 '15 at 9:25

You can revoke “ownership” of the program from the shell with the disown built-in:

# press Ctrl+Z to suspend the program

However this only tells the shell not to send a SIGHUP signal to the program when the shell exits. The program will retain any connection it has with the terminal, usually as standard input, output and error streams. There is no way to reattach those to another terminal. (Screen works by emulating a terminal for each window, so the programs are attached to the screen window.)

It is possible to reattach the filedescriptors to a different file by attaching the program in a debugger (i.e. using ptrace) and making it call open, dup and close. There are a few tools that do this; this is a tricky process, and sometimes they will crash the process instead. The possibilities include (links collected from answers to How can I disown a running process and associate it to a new screen shell? and Can I nohup/screen an already-started process?):

share|improve this answer
disown removes the process from the job-control list. – richard Apr 15 '15 at 14:39
Why not disown -h? – Cees Timmerman Jun 17 '15 at 15:18
@CeesTimmerman That leaves the job in the shell's job table, but what's the advantage of that? – Gilles Jun 17 '15 at 15:20
@Gilles: so you can still fg or kill it, and see if it ends on its own. – Peter Cordes Aug 11 '15 at 20:47
What mentioned utilities work with a group of processes (e.g. bzcat a.bz2 | grep text)? Man for reptyr says that it does not support moving the processes with children. – dma_k Oct 18 '15 at 9:17

To move a process between terminals or to reattach a disowned, you can use e.g. reptyr.

share|improve this answer
Yeah that saved it, thanks! I read the author's website how it works better than similar or older tools eg. for ncurses programs. – Marcos Mar 8 '12 at 15:19
This is awesome; it should solve a friend's predicament of constantly losing her work by running it straight in ssh and then needing to get on a train. "Oops, forgot to use screen. Again." – Adam Katz Jan 16 '15 at 5:13
+1 Although the accepted screen answer is of course ideal, it doesn't actually answer the question, which specifically requests a way to move a currently running process to screen or the like. Also see this answer: serverfault.com/a/284795 – py4on Apr 18 '15 at 21:15

My favorite solution is using tmux, you could detach the session, and re-attach it in another terminal.

When you detached from previous session, you can safely close the terminal; later use tmux attach to get back to the session, even if you logged out.

share|improve this answer
you also can share your session with ur friend and use multiple windows and panes and so much more! love it ^_^ – kitty Sep 24 '13 at 8:03
example of using please? – Vitaly Zdanevich Feb 20 at 0:55

There's also a small utility called retty that lets you reattach running programs to another terminal.

share|improve this answer

I don't use it regularly, but neercs claims to support this. It's a screen-like program with miscellaneous fancy features like better pane management, but the main thing it offers is the ability to import a process into a pane

share|improve this answer
Interesting. It does play dirty (ptrace), but it doesn't just manipulate the file descriptors, it forks the process. It's able to grab find /, but crashed an interactive bash. – Gilles Nov 13 '10 at 22:20
@Gilles I can't remember how it went when I tried, but it doesn't have a great reputation, I'm told it fails pretty regularly – Michael Mrozek Nov 13 '10 at 22:25

"injcode" from ThomasHabets seems to be exactly the thing I need:


The injcode program allows arbitrary code to be injected into a running process, whether or not you knew beforehand and were running screen or tmux

From the README:

Example 1: move irssi from one terminal to another

Maybe move it into a screen.

First start irssi in one terminal.

Run injcode in another terminal: $ injcode -m retty

Irssi should now be moved to the second terminal, including having a new controlling terminal.

share|improve this answer

If you just want to pause it and restart afterwards, you can use kill with STOP or CONT signal.

At first find out the processes PID with

$ ps aux

Then send the signals to that PID listed to the process

$ kill -STOP <PID>

$ kill -CONT <PID>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.