Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How does one detach a process from a terminal?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
paperwings
Tux's lil' helper
Tux's lil' helper


Joined: 14 Jan 2003
Posts: 137
Location: Boston, MA

PostPosted: Tue Jul 08, 2003 3:17 pm    Post subject: How does one detach a process from a terminal? Reply with quote

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
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Tue Jul 08, 2003 3:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
kRock
n00b
n00b


Joined: 28 May 2003
Posts: 73
Location: portland, or

PostPosted: Tue Jul 08, 2003 9:54 pm    Post subject: more useful screen commands / options Reply with quote

^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
View user's profile Send private message
grant.mcdorman
Apprentice
Apprentice


Joined: 29 Jan 2003
Posts: 295
Location: Toronto, ON, Canada

PostPosted: Tue Jul 08, 2003 10:46 pm    Post subject: Detach background job (in bash) Reply with quote

Code:
app &
disown %app


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
View user's profile Send private message
paperwings
Tux's lil' helper
Tux's lil' helper


Joined: 14 Jan 2003
Posts: 137
Location: Boston, MA

PostPosted: Wed Jul 09, 2003 12:32 am    Post subject: Reply with quote

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
View user's profile Send private message
sessionID
Apprentice
Apprentice


Joined: 11 Nov 2002
Posts: 266
Location: hungary

PostPosted: Wed Jul 09, 2003 11:22 am    Post subject: Reply with quote

I use at to emere on remote machine & disconnect.
_________________
((( WeFunk )))
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum