Possible Duplicate:
Can I nohup/screen an already-started process?
On Unix (specifically, Linux), I've started a job in a regular ssh->bash session. I'd like to leave work soon, but I now realize that the job is going to take several hours.
If I had just started this job in screen, I could detach and go home. But I didn't.
Is there any way to disconnect the job from its ssh session, so I can shut down my computer, (dropping the TCP connection and killing the ssh session), and yet have the program keep running?
I don't care about its output -- in fact, I redirected stdout to a file. I just want it to run to completion.
You can press
ctrl-z
to interrupt the process and then runbg
to make it run in the background.You can show a numbered list all processes backgrounded in this manner with
jobs
.Then you can run
disown %1
(replace1
with the process number output byjobs
) to detach the process from the terminal.In spite of the name, the process will still be owned by you after running
disown
, it will just be detached from the terminal you started it in.This answer has more information
I believe the command you are looking for is "disown"
Use
Is beautiful:
and exit of this terminal, a task proceed to be continued...
From within your bash shell:
Then, to continue running the job in background:
Later, you can type
jobs
to see if your process is still running.When using reptyr inside screen, you can move the process (or its output) into screen.
I have taken to setting up
screen
to auto-run when I connect to hosts I use regularly, to avoid this issue.http://tlug.dnho.net/?q=node/239 is one way of doing it, though there are other variations out there.
Has saved me once or twice when I've had an unexpected disconnection mid-session and would otherwise have forgotten to start
screen
before I started something long-winded.Using crtl-Z then bg or using & when running the command is not reliable at 100%. It will work in most case but may not work as expected in some case (I/O usage, ...).
Screen is a reliable solution.
If you are using bash, you can suspect with control-Z and background with bg.
Job control (from man bash)
help bg
help jobs
If you know beforehand that you want to have it running in the background, the unix command at is a good option. It starts commands in the background at scheduled time, just like a cron job that does not repeat. Depending on your distribution, you might need to install it and to start the atd daemon.