View previous topic :: View next topic |
Author |
Message |
paperwings Tux's lil' helper
Joined: 14 Jan 2003 Posts: 137 Location: Boston, MA
|
Posted: Tue Jul 08, 2003 3:17 pm Post subject: How does one detach a process from a terminal? |
|
|
Okay I have asked this question on multiple IRC channels, and no one seems to know. I've had good luck here, though.
I have a research code that requires about 3-5 hours of runtime. How can I start the program from an SSH session from my home computer, detach it, but leave it running, and then close the SSH session?
I have tried the following:
1) Running in the bg using & -- still ends the program when the session is closed
2) expect -- but this pauses the program until you re-open the shell. I need it to keep running
3) VNC -- this works, but it seems clumsy.
I know there is an obvious, head-smacking way to do this. It seems like a fairly common task, especially in the past when everything required hours of runtime.
Thanks! |
|
Back to top |
|
|
Naan Yaar Bodhisattva
Joined: 27 Jun 2002 Posts: 1549
|
Posted: Tue Jul 08, 2003 3:28 pm Post subject: |
|
|
If your program does not need console input, you can do:
Code: |
nohup <program> < /dev/null &
|
This should allow you to detach you ssh session. If this does not work, you can emerge screen and then run your program within a screen session as follows:
Code: |
screen
<program>
^a^d # detaches the screen session
exit # from the ssh session
|
To get back to your old session, just do "screen -r" once you log back in through ssh. |
|
Back to top |
|
|
kRock n00b
Joined: 28 May 2003 Posts: 73 Location: portland, or
|
Posted: Tue Jul 08, 2003 9:54 pm Post subject: more useful screen commands / options |
|
|
^a^c creates a new screen
^a^n cycles between screens (previous)
^a^p cycles between screens (next)
screen -d -r will detach a currently attached screen session and bring it to your current terminal
screen -r resumes a detached session
See man screen for more options. _________________ aob on irc. |
|
Back to top |
|
|
grant.mcdorman Apprentice
Joined: 29 Jan 2003 Posts: 295 Location: Toronto, ON, Canada
|
Posted: Tue Jul 08, 2003 10:46 pm Post subject: Detach background job (in bash) |
|
|
Or disown %jobnum
If your host system is not Linux, the shell may not be bash. Other shells don't implement this, as far as I know, in which case you need to use nohup.
screen is probably overkill for what you want.[/b] |
|
Back to top |
|
|
paperwings Tux's lil' helper
Joined: 14 Jan 2003 Posts: 137 Location: Boston, MA
|
Posted: Wed Jul 09, 2003 12:32 am Post subject: |
|
|
Thanks. It turns out the nohup route worked perfectly. No more waiting until the next day to restart my code when I realize at 9pm I had coded a bug! |
|
Back to top |
|
|
sessionID Apprentice
Joined: 11 Nov 2002 Posts: 266 Location: hungary
|
Posted: Wed Jul 09, 2003 11:22 am Post subject: |
|
|
I use at to emere on remote machine & disconnect. _________________ ((( WeFunk ))) |
|
Back to top |
|
|
|