ProcessWhat is it?JobWhat is it? InLinuxEverything running on the system can be called a process. For example, a simple helloworld program, input the ls command on the terminal, and so on.
A normal running process is called a job. A job can start multiple processes. For example, the job ls-lrt | grep *. txt starts two processes.
Commands related to processes and jobs include kill, disown, wait, fg, bg, and jobs.
Fg, bg, and jobs only accept the job number as the parameter.
Kill, disown, and wait can accept the job number as the parameter and the acceptable process number as the parameter.
The jobs command displays the status of started jobs in the Current shell environment.
- [Alex @ cgdp alex] $ sleep 100 &
-
- [1] 6273
-
- [Alex @ cgdp alex] $ ps
-
- PID TTY TIME CMD
-
- 6230 pts/0 00:00:00 bash
-
- 6273 pts/0 00:00:00 sleep (process to be deleted)
-
- 6274 pts/0 00:00:00 ps
-
- [Alex @ cgdp alex] $ kill-9 6273
-
- [Alex @ cgdp alex] $ ps
-
- PID TTY TIME CMD
-
- 6230 pts/0 00:00:00 bash
-
- 6275 pts/0 00:00:00 ps
-
- [1] + Killed sleep 100 (the process has been deleted)
-
- The disown command can be used to delete a job.
-
- [Alex @ cgdp alex] $ ls-l | sleep 200 &
-
- [1] 6326
-
- [Alex @ cgdp alex] $ jobs
-
- [1] + Running ls -- color = tty-l | sleep 200 &
-
- [Alex @ cgdp alex] $ disown % 1
-
- [Alex @ cgdp alex] $ jobs
-
- [Alex @ cgdp alex] $
The kill command can be used to terminate a process.
The fg command puts the jobs running in the background to the foreground, and bg restarts a suspended job.
You can use CTRL + z to suspend the current process to the background, execute some other operations, and then use fg to re-return the suspended process to the foreground.
Use bg to put the suspended process in the background) to continue running.
Run the wait command to stop the script until all the jobs running in the background are completed, or until the job with the specified job number or process number is finished.
Use the wait command to prevent the script from exiting before the background job is completed (this will generate an orphan process.