Monday, December 10, 2012

Command for linux background processing


Perfect for long running batch jobs on a remote server over unreliable connections or if you want to bring your laptop home (instead of keeping that terminal running).

1) screen
   ------------
Log in and run

screen -t title_of_your_choice

Do the same thing again if you want to create another window.
All the following screen commands are preceeded by Ctrl-a (i.e. first press ctrl-a then the shortcut below)
  • 0-9 – switch to window by id
  • Ctrl-n – next window
  • Ctrl-a – previous window
  • d – quit screen (leaving it running)
  • k – kill window
The next day, log in as usual and attach to the screen session using

screen -x

2) nohup
    ----------

 nohup utility which allows to run command./process or shell script that can continue running in the background after you log out from a shell:

Log in and run

 nohup command-name &

Where,
  • command-name : is name of shell script or command name. You can pass argument to command or a shell script.
  • & : nohup does not automatically put the command it runs in the background; you must do that explicitly, by ending the command line with an & symbol.


1 comment:

suresh chowdary said...

sankar-- you had given a good topics in this blog. please elaborate more examples. like below.

#nohup scriptname &
| |
| |
#command ./logs.sh &