Linux fg bg commands usage and examples

Overview

Linux fg bg commands usage and examples using CTRL-Z and jobs command.
Move a process between background and foreground modes with paused and running states.

Usage and examples

Pause a process

When running a process you can use CTRL-Z to pause the process and free the current shell instance:
Linux fg bg commands ctrl-z-stop

Linux jobs command

To view the stopped jobs use the jobs command:
[code]jobs[/code]
You should receive something like this (Job number, Status, Command):
[code][1]+ Stopped ls –color=auto -l –color=auto -lla -R /[/code]

Run a process in the background

You can start a process in the background from the start using an ‘&’ mark at the end of the command:
[code]cp /source /destination &[/code]

linux fg bg commands

To move a job to the foreground execution (for example job 1):
[code]fg 1[/code]
To move a job to the background execution (for example job 1):
[code]bg 1[/code]

Kill paused jobs

To kill a paused job you can use the kill command followed by the job number (for example job 1):
[code]kill %1[/code]

Enjoy

Leave a Reply

Your email address will not be published.

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.