Linux and Unix are multi-task operating systems, that is, a system can run multiple tasks (processes) within the same period of time ). In this new blog series, I will list related Linux and Unix job control commands, you can execute multiple tasks in Bash, Korn, and POSIX shell.
What is job control?
Job control is not only able to stop/suspend (stop/suspend) processes being executed (commands), but also can continue/wake (continue/resume) to execute every process you need. This can be done with shell or POSIX shell such as your operating system and bash/ksh.
WHO provides an environment for Job control?
Bash/Korn shell, or POSIX shell, provides the job control environment.
Say hello to the job table.
Your shell will have a form for the current job, called a job table. When you type a command, shell assigns it a jobID (also called JOB)SPEC ). A jobID or JOBSPEC is only a small integer.
#1: Create your first Linux/Unix job
I want to run a command named xeyes, which will display two oval eyes on the screen, enter: $ xeyes &
Output example:
Fig.01: run the xeyes command in the background
I use the & symbol to run a job in the background. Shell prints a line of information similar to the following:
- [1] 6891
In this example, two numbers are output, respectively:
- 1: The Job Number of the xeyes task executed in the background is 1.
- 6891: process ID of Job 1.
I am executing some more jobs:
- # Start a text editor, X system load display, and sleep command ##
- Gedit/tmp/hello. c &
- Xload &
- Sleep 100000 &
#2: List the current job
To view the status of the current shell activation task, enter:
- $ Jobs
- $ Jobs-l
The output is as follows:
- [1] 9379 Running xeyes &
- [2] 9380 Running gedit/tmp/hello. c &
- [3]-9420 Running xload &
- [4] + 9421 Running sleep 100000 &
Brief description:
Field |
Value |
Description |
Example |
1 |
[1] |
JobID or JOB_SPEC-work number must be used with fg, bg, wait, kill, and other shell commands. You must add a percent sign in the work number Prefix :(%). Plus sign (+) Identifies the default or current job. Minus sign (-) Indicates the previous job. |
% 1 Fg % 1 Kill % 2 |
2 |
9379 |
Process ID-the unique ID sign that is automatically created and assigned to each process. |
Killed 9379 |
3 |
Running |
Status-job status: Running-The job is running and has not been suspended by external signals. Stopped-The job has been suspended. |
N/ |
4 |
Xeyes & |
Command-commands provided by shell. |
Script & Firefox url & |
You can also use the ps name to list the processes running in the current system:
- $ Ps
#3: Stop or suspend a running job
Press the [Ctrl]-[Z] key or use the kill command, as shown below:
- Kill-s stop PID
For example, start the ping command and press Ctrl-Z to stop the ping command job:
Animated gif 01: Pending ping command job