Wednesday, March 25, 2009

Running jobs in background

When you login to the linux machine, the shell creates three I/O channels that will be used by all the processes spawned from that shell. The I/O channels are stdin (standard input), stdout (standard output) and stderr (standard error).

Jobs can be put into background by using ^z and 'bg' commands. These job will be using the three I/O channels which we discussed above.

Once you log out from the shell those I/O channels are destroyed even though they are used by the job running in the background. The operating system will inteligently reassign the I/O channels to '/dev/null', means that all the output is dumped to the endless pit, and the jobs will not be shown in the jobs list, available while using the 'jobs' command , and also you will not have any trace of the process (will not dump the output to the console) even though it shows up in the process list 'ps -elf'.

To have a better idea about the process running in the background, start the process in the background using 'nohup'.
eg: $ nohup tail -f /var/log/messages > message.out &
$ tail -f message.out

OR, you can use of the 'screen' command as discussed some where in this blog.