Run and disable SSH in the linux background to view background tasks.

Source: Internet
Author: User

Fg, bg, jobs, &, nohup, ctrl + z command

I ,&

At the end of a command, you can put the command in the background for execution, such as gftp &,

2. ctrl + z

You can put a command that is being executed in the foreground to the background, and it is paused and cannot be executed.

Iii. jobs

View the number of commands currently running in the background

The jobs-l option displays the PID of all jobs. jobs can be in running, stopped, and Terminated State, but if the job is Terminated (kill ), the shell deletes the process ID of a task from the List known to the Current shell environment; that is, the jobs command displays information about the running or suspended tasks in the background in the Current shell environment;

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

Change a command suspended in the background to continue (executed in the background)

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)

Transfer the task to the background for running:

Ctrl + z; then bg, the process will be moved to the background for running, and the terminal will continue to accept the command.

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 the changes are the current task.

Vi. nohup

If you are running a process and you think the process will not end when you exit the account, you can use the nohup command. This command can continue running the corresponding process after you exit the account/Close the terminal.

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.

Process suspension (pause)

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;

Use jobs to view tasks. Disable using fg % n.

Related Article

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.