Linux bash builtin commands jobs fg bg and more
 
BASH has builtin commands that do not require any external programs to run. We can list those commands by running
 $ compgen -b 
We can get help on each one of this command by running
 $ help <Command Name> 
For example we may run
$ help help
$ help jobs
$ help bg
$ help fg 
etc.
Now let's find the keyboard setting sequences of suspend (susp) and interrupt (intr), run
 $ stty -a 
If we get something like:
 speed 38400 baud; rows 27; columns 105; line = 0;
	 intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D;
	 eol = ; eol2 = ; swtch = ;
	 start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
	 werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
	 -parenb -parodd -cmspar cs8 -hupcl -cstopb cread
	 -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck
	 -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel
	 iutf8
	 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel
	 nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe
	 echok -echonl -noflsh -xcase -tostop -echoprt echoctl
	 echoke -flusho -extproc 
then ^C (Control-C) is the interrupt to abort (intr=^C) key sequence and ^Z (Control-Z) is the suspend key sequence.

When we run a command on the shell it automatically run in the foreground, thus we cannot use the terminal. We can halt (suspend) the program by holding control-z. We can then view all jobs running in the terminal by running

$ jobs
Our halted program would appear in a list. Suppose that our halted program is the first program, we may continue running the program in the background and continue to use the terminal by running
$ bg %1
Alternatively we may send this program once again to foreground by running
$fg %1
If we chose to bring the program to the foreground we won't be able to use the terminal.
We may also run a command, say firefox, and send stdout and stderr to the bit bucket by running
$ firefox &>/dev/null &
This command (firefox) will appear in the jobs list and we may, as before, bring it to the foreground.

 
Disclaimer Privacy