Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have some heavy, long processes running on remote Linux machines. I use my laptop to SSH to these machine and run the processes from my couch.

BUT, when I want to shutdown my laptop, I am in trouble since the remote processes are killed.

I did my research and found out that "screen" is a great solution for me, it is! (As long as I don't SHUTDOWN my laptop). Isn't there a way to "persist" the "screen" sessions so I can shut it down and then re-attach to a session?

share|improve this question

migrated from stackoverflow.com Aug 11 '10 at 0:15

This question came from our site for professional and enthusiast programmers.

    
Are you running screen on the remote Linux systems? –  Sam Miller Aug 10 '10 at 23:07
    
is it possible to background the processes? –  ennuikiller Aug 10 '10 at 23:09

6 Answers 6

It sounds like you are running the screen session on your laptop. Then sshing from that screen session to the remote host(s). Shutting down the laptop will kill the local screen process, which in turn kills the ssh session.

What you want to do is ssh from your laptop to the remote host(s). Then start a screen session on the remote host. When you laptop is turned off, the ssh session will die, but the remote screen session will persist.

The next time you log in to the remote system, you can re-attach to the screen session with "screen -r" or if you have multiple screen sessions "screen -r < pid >".

Note: if you forgot to detach from the remote screen session before ssh is killed, the screen session may think it is still attached. In this case, you'll need to do "screen -dr < pid >" to detach the session first.

share|improve this answer
6  
+1 for guessing the problem and solving it ;-) –  sleske Aug 11 '10 at 1:30
4  
By the way, if I remember correctly, pressing Ctrl+A followed by D when you're in screen will detach the screen session. –  David Z Aug 11 '10 at 1:35
    
@David this is correct, you can also just close your terminal or ssh session and the screen will remain open. "screen -raAd" will reattach. –  Chris Aug 30 '10 at 12:08
    
How can I start a screen session on the remote host? –  stupidity Oct 2 '13 at 11:41

You can use nohup to start a process that shall continue to run after you have logged out from a machine. That might be what you are looking for.

share|improve this answer
    
For an already-running process, you can do ^Z and then disown to create what I believe is an equivalent effect. disown is a bashism that may or may not be available on other shells. –  intuited Aug 11 '10 at 0:22
    
+1 for nohup. The trouble with ^Z is that it pauses the process. There's no way to background a process but keep it running without a hiccup. –  detly Aug 11 '10 at 3:55

The point of screen is to run it on the server and detach with CTRL + A + D.

share|improve this answer

If these servers have an ILO/DRAC/Other remote KVM, etc you may be able to connect to the console and interact there. Since the sessions initiated are essentially local, dropping the connection from your laptop won't do a thing.

share|improve this answer

If you detatch the remote session in screen, you can safely shut down your laptop.

share|improve this answer
    
Not sure if it's universally obvious that the screen session being detached from must be on the remote server. –  intuited Aug 11 '10 at 0:21
    
Thanks, I added an adjective. –  chryss Aug 16 '10 at 10:49

Use nohup. Another choice to use VNC. Create VNC session on the server. Then connect to it whenever you work on. (More useful when the long process is using some GUI - an IDE for example)

share|improve this answer

Your Answer

 
discard

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