Process management system

                                                                  Process management system                          

 

Case 1: View process information

1.1 problem

In this example, view the process required to master the information, with the necessary tools to do the following command:

  1. Find out process PID number value of gdm
  2. Listed by the process of sub-tree structure information gdm process begins
  3. Find out the process parent sshd process of the PID number / name of the process
  4. View the current system's CPU load / process the amount of information

1.2 program

The main tool command to see the process:

  • ps aux, ps -elf: view the process static snapshot
  • top: View the process of dynamic ranking
  • pstree: tree structure of the relationship between the viewing process and the process
  • pgrep: name or condition according to the specified retrieval process

Step 1.3

This case needs to be achieved in the following steps.

Step one: Identify the process gdm PID number value

Use the pgrep command to specify the name of the query process, the -l option to display the PID number, -x exactly match the process name:

  1. [root@svr7 ~]# pgrep  -lx gdm
  2. 1584 gdm  

Step two: List of process sub-tree structure information gdm process begins

Use pstree command, it can provide a user name or PID values as parameters. Gdm through the front step of the process known as PID 1584, the following operations can list the processes gdm process tree structure:

  1. [root@svr7 ~]# pstree  -p  1584
  2. gdm(1584)-+-Xorg(1703)
  3. |-gdm-session-wor(2670)-+-gnome-session(2779)-+-gnom+
  4. |                        |                      | - gnom +
  5. |                        |                      | - { gno +
  6. |                        |                      | - { gno +
  7. |                        |                      ` - { gno +
  8. |                       |-{gdm-session-wor}(2678)
  9. |                       `-{gdm-session-wor}(2682)
  10. |-{gdm}(1668)
  11. |-{gdm}(1671)
  12. `-{gdm}(1702)

Step three: Find the process parent sshd process of the PID number / name of the process

To view the parent process PID, you can use the command ps -elf, simple grep to filter. Sshd process to find the row that corresponds to the PID PPID value is the number of its parent process. For convenience visualize recommended ps listed first header row, separated by semicolons and then perform the filtering operation.

  1. [root@svr7 ~]# ps  -elf  |  head  -1 ; ps  -elf  |  grep  sshd
  2. F S UID         PID   PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
  3. 4 S root       1362      1  0  80   0 - 20636 poll_s Jan05 ?        00:00:00 /usr/sbin/sshd –D
  4. ..  ..                                  // can learn the process sshd parent process PID is 1

And then based on the results of pstree -p filtering, you can learn the process with PID 1 name for systemd:

  1. [root@svr7 ~]# pstree  -p  |  grep  '(1)'
  2. systemd ( 1 ) - + - ModemManager ( 995 ) - + - { ModemManager } ( 1018 )

Step Four: View the current system's CPU load / process the amount of information

Use the top command, you can look directly at the beginning; or top number -n:

  1. [root@svr7 ~]# top
  2. top - 15:45:25 up 23:55,  2 users,  load average: 0.02, 0.03, 0.05
  3. Tasks: 485 total,   2 running, 483 sleeping,   0 stopped,   0 zombie
  4. % People ( s ):   1.7  us ,   1.0  sy ,   0.0  cm ,  97.3  id ,   0.0  times ,   0.0  hi ,   0.0  si ,   0.0  st
  5. KiB Mem :  1001332 total,    76120 free,   419028 used,   506184 buff/cache
  6. KiB Swap:  2097148 total,  2096012 free,     1136 used.   372288 avail Mem
  7. .. ..

Observation Tasks: 485 total part, it indicates the amount of process information.

Observation load average: 0.02, 0.03, 0.05 part, means that the CPU processor last minute, 5 minutes, 15 minutes in the averaging process requests (multicore CPU, this should be divided by the number of cores).

For multi-core CPU host, to display, respectively, each CPU core occupancy, can be switched in the key numbers in a top interface:

  1. [root@svr7 ~]# top
  2. top - 15:47:45 up 23:57,  2 users,  load average: 0.02, 0.03, 0.05
  3. Tasks: 485 total,   2 running, 269 sleeping,   0 stopped,   1 zombie
  4. Cpu0   :   0.6 % us ,   7.8 % sy ,   0.0 % ,  91.6 % ,   0.0 % % ,   0.0 % hi ,   0.0 % ,   0.0 % st
  5. Cpu1   :   0.7 % us ,   3.7 % sy ,   0.0 % Ni ,  95.6 % id ,   0.0 % now ,   0.0 % hi ,   0.0 % si ,   0.0 % st
  6. Cpu2   :   0.7 % us ,   1.7 % sy ,   0.0 % Ni ,  97.6 % id ,   0.0 % now ,   0.0 % hi ,   0.0 % si ,   0.0 % st
  7. Cpu3   :   0.3 % us ,   1.0 % sy ,   0.0 % Ni ,  98.3 % id ,   0.3 % now ,   0.0 % hi ,   0.0 % si ,   0.0 % st
  8. Mem:  16230564k total, 15716576k used,   513988k free,   326124k buffers
  9. Swap:  8388604k total,   220656k used,  8167948k free, 11275304k cached
  10. .. ..

Case 2: the process of scheduling and termination

2.1 problem

In this case to terminate the process required to master scheduling and operations, with the necessary tools to complete the following tasks:

  1. Run "sleep 600" command, and then open another terminal, to identify and kill PID sleep program
  2. Run multiple vim program and are placed in the background and then kill all the vim processes
  3. su to zhsan user, and then open another terminal, user force kick zhsan

2.2 program

The main tool and process scheduling command termination:

  • Command Line &: the command line to run in the background
  • Key combination Ctrl + z: suspend the current process (suspended and transferred to the background)
  • jobs: Lists the current user terminal of the current background task
  • bg ID: starts the specified number of background tasks
  • fg Number: Specifies the number of background tasks will be transferred to the foreground
  • kill [-9] PID ...: kill PID value of the specified process
  • kill [-9]% n: n th kill background tasks
  • killall [-9] process name ...: kill all processes with the specified name
  • pkill: kill the process specified name or condition

Step 2.3

This case needs to be achieved in the following steps.

Step one: According to the PID to kill the process

1) open the sleep test process

  1. [root@svr7 ~]# sleep 600
  2. .. .. @ enters 600 second wait state

2) identify the PID of the process of sleep

Open another terminal, PS and filtered AUX process information (as the second PID value):

  1. [ Root @ svr7 ~] # ps aux   |   grep sleep
  2. root      32929  0.0  0.0   4312   360 pts/1    S+   17:25   0:00 sleep 600

3) to kill the specified process PID

  1. [root@svr7 ~]# kill  -9  32929

Return the original terminal will find the sleep process has been killed:

  1. [root@svr7 ~]# sleep 600
  2. Killed

Step two: Kill multiple processes based on process name

1) open multiple vim processes in the background

  1. [root@svr7 ~]# vim  a.txt &
  2. [1] 33152
  3. [root@svr7 ~]# vim  b.txt &
  4. [2] 33154
  5. [ 1 ] +   stopped               Vim A . TXT
  6. [root@svr7 ~]# vim  c.txt &
  7. [3] 33155
  8. [ 2 ] +   stopped               Vim B . TXT

2) Confirm vim process information

  1. [root@svr7 ~]# jobs  -l
  2. [ 1 ]   33152  Stop ( TTY output )      Vim A . TXT
  3. [ 2 ] -  33154  Stop ( TTY output )      Vim B . TXT
  4. [ 3 ] +  33155  Stop ( TTY output )      Vim C . TXT

3) Forced to kill all processes named in vim

  1. [root@svr7 ~]# killall  -9  vim
  2. [ 1 ]    has been killed               vim A . TXT
  3. [ 2 ] -   have been killed               vim b . TXT
  4. [ 3 ] +   has been killed               vim c . TXT

4) The results confirm the kill process

  1. [root@svr7 ~]# jobs  -l
  2. [root@svr7 ~]#

Step three: kill all processes belonging to the specified user

1) Login to test the user zhsan

  1. [root@svr7 ~]# useradd  zhsan
  2. [root@svr7 ~]# su  -  zhsan
  3. [ Zhsan svr7 @ ~] $

2) open another terminal, log in as root, look for processes belonging to the user zhsan

  1. [root@svr7 ~]# pgrep  -u  zhsan
  2. 33219
  3. [ Root @ svr7 ~] # pstree   - up   33219                               // check process tree
  4. bash(33219,zhsan)

3) force kill processes belonging to the user zhsan

  1. [root@svr7 ~]# pkill  -9  -u  zhsan
  2. [root@svr7 ~]#

4) return to the terminal user zhsan original log, confirmation has been terminated

  1. [ Zhsan svr7 @ ~] $ has been killed
  2. [root@svr7 ~]#

Guess you like

Origin www.cnblogs.com/qingbai/p/11940647.html