Where to learn Linux development? How does the job control jobs?

Source: Internet
Author: User

Use CTRL + Z to stop a job in the shell run. After the job is stopped, the Linux system will let the user terminate or restart it. You can use the KILL command to terminate a process. Restarting a stopped process requires sending a sigcont signal to it.

The operation to restart, stop, terminate, and resume jobs is called job control. Use job control to fully control how a process runs in a shell environment.

1 Viewing jobs

The key command for job control is the jobs command. The jobs command can view the current jobs handled by the shell:

The script uses the $$ variable to display the PID assigned to the script by the Linux system, and then into the loop, each iteration interval of 5 seconds. Start the first script from the command-line program, and then use CTRL + Z to stop it. Next, use the & symbol to start another job later, and redirect the output of the script to a file so that it does not appear on the monitor.

After the job starts, use the jobs command to view the jobs assigned to the shell. The jobs command displays the job status as well as the job number and the commands used in the job, showing the stopped job. Some of the different parameters used by the jobs command:

The plus and minus signs in the output. Jobs with a plus sign are considered default jobs. If the command line does not specify a job number, it should be the job referenced by any job control command. A job with a minus sign is the job that will become the default job after the current default job is processed. At some point in time, there can be only one job with a plus sign, and only one job with a minus sign, no matter how many jobs are run in the shell. When the current default job is killed, a job with a minus sign before it becomes the default job.

2 Restarting a stopped job

Under Bash job control, you can restart any stopped jobs in the form of a background process or foreground process. The foreground process will control the terminal being processed, so use the feature sparingly. To restart the job in background mode, you can use the BG command with the job number. BG command format: BG job number

Restart the job in the future mode, a command line interface prompt is available to continue processing other commands. To restart in foreground mode, you can use the FG command with the job number: FG job number.

Examples of FG operations:

The job is now running in foreground mode and the command line interface prompt cannot be used when the job finishes.

Where to learn Linux development? How does the job control jobs?

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.