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

Possible Duplicate:
How can I disown a running process and associate it to a new screen shell?

I launched a command that lasts a long time. I had to disconnect so I moved it in the background (with CTRL+Z and bg) before exiting.

Something like this:

$ my_command
***command is beeing executed and is taking a long time***
[1]+  Stopped                 my_command
$ bg
[1]+ my_command &
$ exit

I reconnected and can see the command in the process list but cannot recover with fg.

$ fg
-bash: fg: current: no such job

How do I recover my job in the foreground?

share|improve this question

marked as duplicate by Mat, Renan, jasonwryan, Gilles, warl0ck Sep 26 '12 at 0:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 9 down vote accepted

If you've already started something somewhere, backgrounded it, and now need to attach it to a new terminal, you can use reptyr to re-attach it. (The man page summarises the command as "Reparent a running program to a new terminal".)

The reason you can't see it in the "jobs" command or use "fg" to bring it to the foreground is because these commands are actually built-in to the shell. They don't technically detach the processes from the terminal you're connected with, so when you exit the shell they should exit as well (you should get a warning when you attempt to exit).

share|improve this answer
+1. thanks, i didn't know about repytr. useful....doing what it does manually always seemed too much work to be worth the effort most of the time. – cas Sep 25 '12 at 22:53
works so great... !!! thanks!!! sometimes you need to use 'sudo' to run the command. syntax: "sudo reptyr –s PID " and it brings my python process from other terminal active in the current one. – ihightower Dec 13 '14 at 11:08

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