Where to learn Linux development? How to control Jobs?

Use the Ctrl+Z key combination to stop a running job in the shell. After stopping the job, the Linux system asks the user to terminate or restart it. Processes can be terminated using the kill command. Restarting a stopped process requires sending it a SIGCONT signal.

The operations of restarting, stopping, terminating, and resuming jobs are called job control. Use job control to have complete control over how processes run in a shell environment.

1 View assignments

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

The script uses the $$ variable to display the PID assigned to the script by the linux system, and then enters a loop with a 5 second interval between each iteration. Start the first script via the command line program, then stop it with the Ctrl+Z key combination. Next, start another job as a background process using the ampersand and redirect the output of the script to a file so that it won't be displayed on the monitor.

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

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 a job that will become the default job after processing the current default job. There can only be one job with a plus sign and only one job with a minus sign at a point in time, no matter how many jobs are running in the shell. After killing the current default job, the job with a minus sign before becomes the default job.

2 Restart the stopped job

Under bash job control, any stopped job can be restarted as a background or foreground process. The foreground process will control the terminal being processed, so use features sparingly. To restart a job in background mode, you can use the bg command with the job number. bg command format: bg job number

The job is restarted in background mode, the command line interface prompt appears, and other commands can continue to be processed. To restart in foreground mode, you can use the fg command with the job number: fg job number.

Example of fg operation:

The job now runs in foreground mode and the command line interface prompt cannot be used until the job is complete.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325328794&siteId=291194637