A brief introduction to the BG and FG commands for Linux

Source: Internet
Author: User
Tags rsync

As we all know, on Windows, we either have a program running in the background as a service, or stop the service. Instead of allowing the program to switch between foreground and background. Linux provides FG and BG commands, allowing us to easily schedule running tasks.
Suppose you find that a program running in the foreground takes a long time, but you need to do something else, you can hang up the program with Ctrl-z, and then you can see the system prompt (the job number in square brackets):

Copy CodeThe code is as follows:
[1]+ stopped/root/bin/rsync.sh


Then we can schedule the program to execute in the background: (the number behind BG is the job number)

Copy CodeThe code is as follows:
# BG 1
[1]+/root/bin/rsync.sh &


View running tasks with the jobs command: #jobs

Copy CodeThe code is as follows:
[1]+ running/root/bin/rsync.sh &


If you want to bring it back to the foreground, you can use

Copy CodeThe code is as follows:
# FG 1
/root/bin/rsync.sh


This way, you can only wait for the task to complete on the console.
FG, BG, Jobs, &, CTRL + Z are all related to system tasks, although these commands are largely not needed now, but they are also useful
One. & is most often used
This is used at the end of a command, you can put this command in the background to execute
Two. CTRL + Z
You can put a command that is executing in the foreground in the background and pause
Three. Jobs
See how many commands are currently running in the background
Four. Fg
Move commands in the background to the foreground to continue running
If there are multiple commands in the background, you can use FG%jobnumber to bring up the selected command,%jobnumber is the ordinal (not PID) of the command being executed in the background through the jobs command.
Five. Bg
A command that pauses in the background changes to continue execution
If there are multiple commands in the background, you can use BG%jobnumber to bring up the selected command,%jobnumber is the ordinal (not PID) of the command being executed in the background through the jobs command.

A brief introduction to the BG and FG commands for Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.