Bg

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search

The bg command is part of UNIX / Linux job control. It is used to restart a stopped background process.

Example

In this example, run ping command in foreground:

ping google.com

Stop Foreground Process

To stop the foreground process called ping press [Ctrl-z] keys. You need to hold down the ['Ctrl] key and type [z].

Sample outputs:

PING google.com (209.85.231.104) 56(84) bytes of data.
64 bytes from maa03s01-in-f104.1e100.net (209.85.231.104): icmp_seq=1 ttl=54 time=42.2 ms
64 bytes from maa03s01-in-f104.1e100.net (209.85.231.104): icmp_seq=2 ttl=54 time=42.2 ms
64 bytes from maa03s01-in-f104.1e100.net (209.85.231.104): icmp_seq=3 ttl=54 time=42.7 ms
^Z
[1]+  Stopped                 ping google.com

List Background Process

To list both background and stopped processes use the jobs command:

jobs

Sample outputs:

[1]+  Stopped                 ping google.com
[2]-  Running                 gedit &

Restart Stopped Process

To restart a stopped background process (this will restart recently stopped process), type:

bg

OR type the following to restart a stopped background process having JOB ID # 10:

bg 10