Job Control

This page describes how you can manipulate processes from a console session.

Starting Processes

To start an application/process you type the name into the prompt, like this:

opera

For this to work, the application needs to be in a folder listed in the environment variable PATH.  To view the folders in this variable, type:

echo $PATH

Generally applications will be put into /usr/bin.  It is not a good idea to alter the value of PATH, or you could break many, many things.  Instead, if you wish to run an application that is in a different location you need to specify the path explicitly, for example:

/home/rob/opera

./opera

The second command above will attempt to run the application opera from the current location.

The commands listed so far will run applications but you'll not be able to do any more work in the console session, as the processes will be running in the foreground.  To launch a process in the background, use an &:

./my_application &

opera &

 

Viewing Background Processes

Once you've started one or more processes running in the background you can view them all with the jobs command:

~/$ jobs
[1]-  Running kate &
[2]+  Running vlc &

The number in the angle brackets denotes the job number.  Use the argument -l to list the PID at the same time.

 

Changing Between Background and Foreground

You can bring a background job to the foreground using fg.

~/$ fg 1
kate

This will tie up the terminal so that you can no longer use it, but bring the specified job to the foreground.  To move it back again, use ^Z (that is, Control+Z) to pause it and then bg to run it again in the background:

~/$ fg 1
kate

[1]+  Stopped kate
~/$ jobs
[1]+  Stopped kate
[2]-  Running vlc &
~/$ bg 1
[1]+ kate &
~/$ jobs
[1]-  Running kate &
[2]+  Running vlc &
~/$

Killing a Job

You can easily kill a job using the kill command.  You can pass kill the PID or job number in order to kill a process.  To kill job 1, use the following syntax:

~/$ kill %1