Although I am intimately familiar with ssh-ing, I realized yesterday that I still don’t know how to ssh into a remote computer and start running something in such a way that it will keep on running even after I turn my laptop off. I asked a fellow student who didn’t know how off the top of his head either, and so I decided to Google it. As I was making my way to Google I realized that I have quite an extensive network of astronomers on Facebook, and maybe I should throw that question out to them. I posted a status update, and then had to run to a lunch talk. When I returned an hour later there were loads of responses. (I really need to remember that trick when I have other questions about science, IDL, etc.)
I distilled all the comments down to two easy methods: nohup, and screen.
Nohup is short for “no hangup”, or no HUP, and it basically will tell something to run, and ignore the HUP signal, which is how terminal warns dependent processes of logout. I didn’t try using nohup, but one of my favorite astronomers, David Anderson, provided the following instructions for its use:
( nohup <stuff> ) >& Log &
bash is more like:
( nohup <stuff> ) 2>&1 Log &
Because someone else told me “nohup is so last year” and now the cool kids are using screen, I went straight to that one (peer pressure, what can I say). Screen is a little harder to google, but I managed to figure out how it works. When you run the screen command it creates a window with a shell in it that you can then use to do whatever you want. You can give the window a name, and then hide it, and the programs inside will continue to run (detached). You can create as many windows as you want and they will run independently of each other. You can also call up a list of window, kill windows, retrieve them, etc. Screen is probably a lot more powerful than the simple ssh sessions I have been using it for, but it’s a good place to start. Here’s a quick step-by-step:
Create a screen:
$ screen -S [name]
Then do something in this window. For example, ssh into a remote computer and run something.
$ Ctrl+a+d will “hide” the window and save the task. It will say [detached]
$ screen -ls shows what screens are currently
There is a screen on:
10000.task (Detached) running
$ screen -r 10000 recover the screen
$ exit to exit screen
[screen is terminating]
So far, screen seems to be working well for me. I will post an update with any new tips, tricks, or warnings that I learn after I have used it for a while.