Tuesday, June 19, 2007

Run program after logout (my version)

There are two ways I know so far:
1. nohup
nohup stands for 'no hang up' for me. For instance:
nohup ./script_run &
Then logout the server and power off your computer.
The script_run will keep running until it finishes or you log back in and stop it (kill the process).

2. screen
screen is rather more powerful tool. It can certainly do more (better) job than running a
program for you after you logout server. Well, that is the only function I am interested from it for now. So, how to use it? Example:
screen ------------This command will give you a new screen. Check xterm title.
Ctrl-a Ctrl-d ------Detach screen, whatever program you run in 'screen' is still running.
You can logout and even power off your computer now.
screen -x ---------Reattach screen. You can use any computer to login the server as the same user when runned screen. Terminal will show whatever program you were running before.

So, three commands: screen; Ctrl-a Ctrl-d; screen -x. Is that simple.
####################################################################
detatch screen from a screen:
ctrl-a
a
d
------------------------
ctrl-a,a is just to send ctrl-a to a screen session within a screen session.
It's all in screen's manpage. I always check manpage before asking Google.

Also, I like to turn on the caption line so I know whether I'm in screen or
not.
For example, put these two lines in your .screenrc
caption always
caption string "%{= RW} [%H] <%n>=%t%=%Y-%m-%d=%c "

No comments: