Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between processes and jobs in Linux

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "what are the differences between processes and assignments in Linux", the content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn "what are the differences between processes and assignments in Linux".

What is the process? What's the assignment? Everything that runs on a Linux system can be called a process. For example, a simple helloworld program, typing ls command on terminal, etc.

A normal running process is called a job, and a job can start multiple processes, such as the job ls -lrt| grep *.txt starts two processes.

Process and job related commands are: kill, disown, wait, fg, bg, jobs

fg, bg, jobs accept only job number as parameter.

kill, disown, wait can accept the job number as a parameter, and can accept the process number as a parameter.

The jobs command displays the status of jobs started 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 (process deleted) The disown command can be used to delete jobs [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.

FG puts jobs running in the background into the foreground and bg restarts a pending job.

You can suspend the current process to the background with CTRL+z, perform something else, and then use fg to put the suspended process back to the foreground (also

bg can be used to put pending processes in the background) to continue running.

The wait command stops the script until all jobs running in the background have finished, or until the job with the specified job number or process number option has finished. may

Use the wait command to prevent the script from exiting before the background job completes, which would create an orphan process.

For example:

Write a simple test script

#!/ bin/sh ls -l& echo "done"

Run:

alex@cgdp shell]$ ./ test done [alex@cgdp shell]$ total 4 -rwxrwxr-x 1 alex alex 30 May 5 21:15 test

Rewrite the test script with the wait command

#!/ bin/sh ls -l& wait echo "done"

Run:

[alex@cgdp shell]$ ./ test total 4 -rwxrwxr-x 1 alex alex 35 May 5 21:19 test done The above is "What are the differences between processes and jobs in Linux" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report