Fg bg and other commands

Source: Internet
Author: User

FG, BG, jobs, &, CTRL + Z are all related to system tasks. Although these commands are rarely used, they are also very practical.

1. & most frequently used

This command is used at the end of a command and can be executed in the background.

Ii. CTRL + z

You can put a command that is being executed on the foreground in the background and pause it.

Iii. Jobs

View the number of commands currently running in the background

Iv. FG

Move the commands in the background to the foreground to continue running.

If there are multiple commands in the background, you can use FG % jobnumber to call up the selected command. % jobnumber is the serial number (not PID) of the command being executed in the background found through the jobs command)

5. bg

Pause a command in the background to continue execution.

If there are multiple commands in the background, you can use BG % jobnumber to call up the selected command. % jobnumber is the serial number (not PID) of the command being executed in the background found by the jobs command)

Use shell commands in Linux to control jobs execution

The following commands can be used to manipulate process tasks:

PS: Lists processes running in the system;

Kill sends signals to one or more processes (often used to kill one process );

Jobs lists the status of started tasks in the Current Shell environment. If jobsid is not specified, the status information of all active tasks is displayed; if the termination of a task is reported (that is, the task state is marked as terminated), shell deletes the process ID of the task from the List known in the Current Shell environment;

BG moves the process to the background );
FG moves the process to the foreground for running (foreground );
Transfer the job to the background for running
If you often work in x graphics, you may have the experience of running a GUI program through Terminal commands. The GUI is displayed, but your terminal remains in the same place, you cannot execute other commands in shell unless you disable the GUI program.
To enable the terminal to continue to accept commands after the program is executed, you can move the process to the background and run the program using the following command: # suppose you want to run xmms
$ Xmms &
In this way, after enabling xmms, the terminal prompt is returned. Currently, xmms is running in the background. However, if you forget to use "&" when running the program and do not want to execute it again, you can use Ctrl + Z to suspend the program first, then, press the BG command to continue running the program in the background.
Concept: current task
If there are two backend task numbers: [1], [2]. If the first backend task is successfully executed, the current task automatically becomes a background task with the background Task Number "[2. So we can conclude that the current task will change. When you enter commands such as "FG", "BG", and "stop", if no quotation marks are added, all changes are made to the current task.
View jobs
Run the jobs or ps command to view the jobs being executed.
The result of running the jobs command. + indicates a current job. The minus table is a job after the current job. The jobs-L option displays the PID of all tasks, jobs can be in the running, stopped, and terminated state. However, if the task is terminated (kill), the shell deletes the process ID of the task from the List known in the Current Shell environment. That is, the jobs command displays information about running or suspended tasks in the background in the Current Shell environment;
Process Suspension
Suspension of background processes:
Run the Stop command in Solaris, run the jobs command to view the job number (assuming num), and then run the stop % num command;
In RedHat, the Stop command does not exist. You can run the command kill-Stop PID to suspend the process;
When you want to re-execute the currently suspended job, you can use BG % num to change the status of the suspended job from stopped to running and still run in the background. When you need to re-execute the job on the foreground, run the command FG % num;
Pending foreground processes:
CTRL + z;
Process Termination
Termination of background processes:
Method 1:
Run the jobs command to view the job number (assuming num), and then run kill % num
Method 2:
Run the ps command to view the job process ID (PID, assumed as PID), and then run the kill PID command.
Termination of the foreground process:
CTRL + c
Other roles of kill
In addition to terminating the process, kill can send other signals to the process. You can use kill-L to view the signals supported by kill.
Sigterm is a signal sent by kill without parameters. It means that the process must be terminated, but whether the process is executed or not depends on whether the process is supported. If the process has not been terminated, you can use the kill-sigkill PID, Which is terminated by the kernel. The process cannot listen to this signal.

 

 

Reference: http://blog.sina.com.cn/s/blog_673ee2b50100iywr.html

Fg bg and other commands

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.