Thursday, 28th August 2008
There's not point setting up jobs to do things if we have to sit there and wait until they complete before we can do anything else. So instead we get them to run in the background, or basically to run without throwing up any output to the window we're working in, so while a job is running you can continue to work away without interference.
$ man info &
[2] 5384
Nothing complex here, the man command can be used to bring up manual pages containing references for nearly all the programs
in the system. Similiar to info but it is more common. In this case we've asked it to bring up the manual page for the info
program, which is kind of ironic given that they are both used to explain how programs are used on the system. The ampersand
"&" is used to send the job into the background. In this case the result is that you have a man page open
with the options for the info program, however nothing is being displayed to the terminal.
Just to explain, since we have a job currently suspended, the info program in the first section, this backgrounded job
is assigned the number 2, but whats that number following it?
[2] 5384
The second number is know as the "process id", its not particularly important at the moment but it'll come in useful later on. So now you know that aside from the job id, each job will have a process id or "pid" for short.
A slightly more useful command that can be backgrounded is as follows
$ nohup wget -bc http://www.compsoc.nuigalway.ie/ &
[3] 5437
nohup: appending output to `nohup.out'
For now the next command will be jobs.
$ jobs
[1]- Stopped info
[2]+ Stopped man info
[3] Done nohup wget -bc http://www.compsoc.nuigalway.ie/
You've seen how to background a job from the command line, now its time to perform that when the job is suspended. We still have the info job from the start of the demo that is currently suspended, so we"re going to move that into the background and see what happens.
To background the most recent job, you just use "bg", but in this case we want to do it for job number 1 and job number 2 is the most recent job, so we have to add an additional bit of data to the command.
$ bg %1
[1]- info &
Just as one final touch just using bg will background the most recent job, if you remember earlier it was stated that the + symbol after the job number indicates the most recent suspended job.
$ bg
[1]+ info &
[2]+ Stopped man info
Basically this is because backgrounding jobs like this just doesn't work, so they get automatically suspended again.
Next we'll learn how to foreground jobs.