Running jobs from terminal in background [foreground and pausing]

This post is concerned with running jobs (one or more programs) in foreground and background using just a terminal. Here, I use firefox as an example to demonstrate the same. <username> on screenshots shown below is scrambled for privacy concerns.

Running programs from terminal

You can always run a  job in foreground by typing a command on to the terminal as

firefox

firefox_1
But once the program starts we lose the bash prompt. Another way to start firefox is to run the program in background. This will return bash prompt as shown below.

firefox &

firefox_2

Pause and resume jobs from terminal

Sometimes you need to pause a job that’s running and return to bash prompt and execute some commands and afterwards resume the original job. Press CTRL+Z to pause the original job and return to command prompt as shown below. This will immediately pause firefox and you will note able to use it for browsing the web.

firefox_3

Case 1:

To resume  firefox in background run

bg %1

firefox_4

This will resume firefox but in background and returns bash prompt as shown above.

Case 2:

To resume  firefox in foreground run

fg %1

firefox_5

This will resume firefox but in foreground, but will not return bash prompt as shown above.

Listing jobs in background and killing them

To list all the jobs running in background run

jobs -l

firefox_6

To kill a job running in background, find job ID (21689) from earlier listing

kill 21689

firefox_7

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s