Uncover the knowledge of Linux background jobs

Source: Internet
Author: User

The basic Linux operation aims to give readers a preliminary understanding of Linux. After the development of Linux, I will describe the Linux background here. Here I will share my personal understanding and discuss it with you. From the operating system perspective, a job is a user task running in a computer system. In unix/linux systems, a job can be defined as one or more commands entered in the command line.

Linux is a real multi-user and multi-task operating system, so you can run multiple tasks at the same time. However, when you start a job on the foreground, both the standard input and the standard output are locked, they are exclusive to the current job until the job ends. Therefore, linux defines two types of jobs: foreground jobs and Linux background jobs.

Foreground jobs

Generally, the programs we run on the terminal are all foreground jobs. Other jobs cannot be started during the running process, and it is quite simple to start foreground jobs. Enter the command and press Enter.

◆ To suspend a foreground job, you only need to press Ctrl + z. This is useful in full-screen editing mode. you can pause the editing job to complete other tasks. After returning to the terminal, we can run jobs-l to view information about the suspended job.
◆ Resume a suspended job and resume a suspended job. You only need to execute the command fg at the terminal.
◆ Terminate a foreground job and terminate a foreground job. Press Ctrl + c. After the job is terminated, press enter to activate the command line prompt.

Linux background job

When a job takes a long time, you may need to run the command in the Linux background to complete other tasks.
◆ Start a Linux background job to start a Linux background job. You only need to add the Symbol & behind the command &. Note that if the job has parameters, the & sign follows the last parameter. No space is left between the end and the end of the command. It should be noted that foreground jobs and Linux background jobs share resources such as keyboards and monitors. In order to separate CPU time slices, Linux background jobs and foreground jobs compete, therefore, any messages sent by Linux background jobs to the monitor will be mixed with messages from the current job, which may be very messy soon. A Linux background job must be moved to the foreground to request user input. It is strongly recommended that the input and output of Linux background jobs must be redirected. It is best to redirect terminal output files or null devices. You can try the Linux background ping command without parameters, for example, ping localhost!
◆ Suspend, restart, terminate a Linux background job. In order to suspend a Linux background job, run the stop command, restart the bg command, and terminate the kill command. Each of the three commands requires a job number of %. You can use jobs to view the job number.
◆ Switching the status of a suspended job in the Linux background before a job can be switched between the previous job and the status of the Linux background. Once a job is suspended, you can run the bg command on the Linux background. To move a Linux background task to the foreground, use the fg command.
◆ Multiple Linux background jobs when multiple Linux background jobs run, the job number must be used to mark the jobs to be processed.

Job Queue

Run the jobs [-l] command to view the current job and its status. Each job has a corresponding job number, current value, and running status.
◆ + In the current value job list.-indicates the current value flag. + "#" Indicates that the current default job is changed. "-" indicates that the current default job is replaced by the current default job after the current default job is completed. Here =,-indicates the process priority. When a job is suspended, it is called the default current value flag. If multiple jobs are suspended, the corresponding id value is assigned in the order of suspension. The first sign to be suspended is the plus sign, the earlier version is the minus sign, which is easy to understand by priority.
◆ You can add the job number parameter to the commands mentioned earlier. The job number starts with "%" and is separated by a space. The default job number can be % + or %. The job that contains the current value of the minus sign can be %-expressed. For example, end the current default job: kill % or kill % +.
◆ A job may be in one of the following three States: foreground, Linux background, and suspended. When a job is started, it runs on the foreground. During the running period, the job can be suspended, terminated, or run until the job stops automatically. The suspended job can also be transferred to the Linux background for further execution. A job can be executed with manual intervention from creation to completion. We can better control our job tasks so that Linux can better serve us and improve work efficiency.

This article focuses on simple concepts, so the key is to practice it on your own. Of course, this is just a reference for new users. Masters can pass!

  1. Will Virtual Technology dominate Linux?
  2. Comprehensive Understanding of Linux kernel cyclic linked list
  3. Command Daquan: Linux File Creation command
  4. Command Daquan: Linux File Creation command
  5. Linux chmod 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.