当前位置:网站首页>Process scheduling and termination

Process scheduling and termination

2022-07-05 01:46:00 *_ Flowers are not strangers_*

One . The main command tool for process scheduling and termination

1. Command line &: Run the command line in the background

2.Ctrl + z Composite key : Suspend current process ( Pause and go backstage )

3.jobs: List the background tasks of the current terminal of the current user

4.bg Number : Start the background task with the specified number

5.fg Number : Transfer the background task with the specified number into the foreground to run

6.kill [-9] PID...: Kill designated PID Value process

7.kill [-9] %n: Kill No n A backstage task

8killall [-9] Process name ...: Kill all processes with the specified name

9.pkill: Kill the process according to the specified name or condition

Two . Case study

1. Kill designated PID process

[[email protected] ~]# sleep 1000 & # Open in the background sleep Mission 
[1] 76672
[[email protected] ~]# ps aux | grep sleep # Filter process information ( The second as PID)
root      76672  0.0  0.0 107948   352 pts/0    S    23:28   0:00 sleep 1000
root      76740  0.0  0.0 112704   960 pts/0    R+   23:28   0:00 grep --color=auto sleep
[[email protected] ~]# kill -9 76672   # Kill designated PID process 
[[email protected] ~]# jobs            #sleep The process has been killed 
[1]+  Killed                  sleep 1000

2. Kill multiple processes according to the process name

# step 1: Open multiple in the background vim process 
[[email protected] ~]# vim a.txt &
[1] 77890
[[email protected] ~]# vim b.txt &
[2] 77915

[1]+  Stopped                 vim a.txt
[[email protected] ~]# vim c.txt &
[3] 77944

[2]+  Stopped                 vim b.txt

# step 2: Confirm the process information 
[[email protected] ~]# jobs
[1]   Stopped                 vim a.txt
[2]-  Stopped                 vim b.txt
[3]+  Stopped                 vim c.txt
# step 3: Force to kill all people named vim The process of 
[[email protected] ~]# killall -9 vim
# step 4: Confirm that the process is killed 
[[email protected] ~]# jobs
[1]   Killed                  vim a.txt
[2]-  Killed                  vim b.txt
[3]+  Killed                  vim c.txt

3. Kill all processes belonging to the specified user

 step 1: Log in to test user 
[[email protected] ~]# useradd test   # Create user 
[[email protected] ~]# su - test      # Switch to test user 
[[email protected] ~]$ 

 step 2: Create a new terminal to manage root Sign in , Search for users test The process of 
[[email protected] ~]# pgrep -u test    # Retrieve the user's PID
84860
[[email protected] ~]# pstree -up 84860 # Check the process tree 
bash(84860,test)

# step 3: Force to kill the process belonging to the user 
[[email protected] ~]# pkill -9 -u test # Kick out the logged in user test

# step 4: Return to the original test terminal , Confirmation has been terminated 
[[email protected] ~]$ Killed

原网站

版权声明
本文为[*_ Flowers are not strangers_*]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141013219534.html