next up previous contents
Next: Sending Signals to Up: Process Management Previous: System usage

Running multiple processes

Now we know how to check for multiple processes running, we can start running multiple processes ourselves.

If we want to run a program in background which does not need any user interaction and does not produce screen output we can use the '&' at the end of the command line to do this:

$ls -Fla > out_dir &
[2] 296
$

The ls command was told to put its output into a file and run in background. The shell tells us that this is the second job in this shell (the first being the editor this document is written in) and the PID of the job is 296. We are immediately returned to the prompt and can issue further commands while the ls is running in background. If we enter the next command or press return after the ls command has finished we get the following message:

$
[2]+  Done                    ls -Fla >out_dir
$

This tells us that the command ls has finished.

To see what jobs are currently running and have been started from our shell we can use the jobs command. This has the advantage against the ps command that it only shows us programs started from this shell.

$jobs
[1]+  Running                 emacs part2.tex &
$

This shows us that job number one is running and the command line used to start it was emacs part2.tex &.

If we are running a program and want to quickly do something else we can stop the current program by typing CTRL-Z. Say we were running the editor program vi. If we stopped it with CTRL-Z we would get the following message:

[2]+ Stopped            vi
$

Typing jobs would show us the following:

$jobs
[1]- Running         emacs part2.tex &
[2]+ Stopped         vi
$

The current job is marked + and the previous job is marked -. To return to the current job we can simply type fggif or to run the current job in background we can type bggif. To access the previous job we can type fg %- or bg %-; any other job can be accessed via its number, eg fg %1, or via its name, eg fg %vi.

So to get back to the vi program, we can type fg or fg %2.



next up previous contents
Next: Sending Signals to Up: Process Management Previous: System usage



Mark O. Stitson
Wed Sep 25 10:45:32 BST 1996