Linux notes: process management

In Windows, you can view the corresponding process information and system resources through the task manager. In Linux, you usually use "ps aux" to view these information.

 

View all processes and system resources
ps aux or ps-le: View all processes, that is, the use of system resources, the former uses the BSD operating system format, that is, Unix system format, a represents the foreground process, u represents the user who created the process, x Indicates a background process. The latter is a Linux standard command format, l means to display detailed information, and e means to display all processes. Which command to use depends on the user's habits, but the former is more commonly used in Linux.
ps aux output interpretation (each line is a system process):

  • USER: The user who created the process.
  • PID: Process ID.
  • % CPU: CPU utilization.
  • % MEM: memory usage.
  • VSZ: The size of virtual memory occupied in KB.
  • RSS: physical memory occupation size, the unit is KB.
  • TTY: The terminal where the process logs in, question mark? Indicates that it is started directly by the system kernel. tty1-tty7 is a local terminal, tty1-tty6 is a local character terminal, tty7 is a local graphical interface terminal, and pts / 0 to pts / 255 represent virtual terminals (can be understood as remote terminals).
  • STAT: process status, this status has many values, common are R (running), S (sleep), T (stop state), s (including child processes), + (in the background).
  • START: Start time.
  • TIME: CPU computing time.
  • COMMAND: The command that produced this process (usually from which process you are running).

View process tree: pstree [options]
options:

  • -p: Display the PID of the process.
  • -u: Display the user of the process.

 

View system health status
top [Options]: View system health status.
Options:

  • -d seconds: Specify the refresh interval of the result of the top command, the default is 3 seconds.

The following commands can be executed in the interactive mode of the top command:

  • ? Or h: Display help in interactive mode.
  • P: Sort by CPU usage, it is also the default item.
  • M: Sort by memory usage.
  • N: Sort by PID.
  • q: Exit top.

The top command starts a few lines of information viewing: the
first line (system information)

  • 12:26:46: Current system time.
  • up 1 day, 13:32: how much time the current system has been running, here means that the machine has been running for 1 day, 13 hours and 32 minutes.
  • 2 users: how many users are currently logged in.
  • Load average: 0.00, 0.00, 0.00: The average load of the system in the previous 1, 5, and 15 minutes. It is generally believed that less than 1 (according to the number of CPU cores, 4 cores are 4), the load is small, otherwise the system has exceeded the load (this information is an important item to view the system health status).

The second line (Tasks: process information)

  • 95 total: The total number of processes in the system.
  • 1 running: the number of running processes.
  • 94 sleeping: the number of sleeping processes.
  • 0 stopped: The process being stopped.
  • 0 zombie: the number of zombie processes (that is, processes that have been ending but have not ended successfully), if not 0, you need to manually check the corresponding zombie process

The third line (Cpu (s): CPU information)

  • 0.1% us: The percentage of CPU occupied by user mode.
  • 0.1% sy: The percentage of CPU used by the system mode.
  • 0.0% ni: The percentage of CPU occupied by the user process whose priority has been changed.
  • 99.7% id: The percentage of idle CPU usage (this information is an important item to view the system health status).
  • 0.1% wa: The percentage of CPU occupied by the process waiting for input / output.
  • 0.0% hi: Percentage of CPU occupied by hard interrupt request service.
  • 0.1% si: The percentage of CPU occupied by the soft interrupt request service.
  • 0.0% st: st (Steal time) virtual time percentage. That is, when there is a virtual machine, the percentage of time the virtual CPU waits for the actual CPU.

The fourth line (Mem: physical memory information)

  • 625344K total: The total amount of physical memory in KB.
  • 571504k used: The amount of physical memory that has been used (this information is an important item for viewing the health status of the system).
  • 53840k free: The amount of free physical memory.
  • 65800k buffers: the amount of memory used as a buffer.

The fifth line (Swap: swap partition swap information)

  • 524280k total: The total size of the swap partition (virtual memory).
  • 0k used: The size of the swap partition that has been used.
  • 524280k free: The size of the free swap partition.
  • 409280k cached: The size of the swap partition used as a buffer.

 

Kill process
kill PID: Terminate the process. It is generally not recommended to use this command to terminate the process. You should use each process's own termination command, such as stop. Only use the system's terminate process command when it cannot be terminated under normal circumstances.
kill -l: View the available process signals.
Commonly used process signals (signal code (signal name)):

  • 1 (SIGHUP): immediately shut down the process, then restart the process after re-reading the configuration file.
  • 2 (SIGINT): Terminate the foreground process, equivalent to Ctrl + C.
  • 9 (SIGKILL): End the program immediately. This signal cannot be blocked, processed, and ignored. It is usually used to forcefully terminate the process.
  • 15 (SIGTERM): The signal to end the process normally, and also the default signal of the kill command. If the program cannot end normally, you can use signal 9 to forcefully end the process.
  • Example: "kill -1 22354" means restart the process with PID 22354.

killall [options] [signal] Process name: terminate the process (including its child processes).
Options:

  • -i: Interactive, will ask whether to terminate a process.
  • -I: Ignore the case of the process name.
  • Example: Commonly used is "killall -9 process name".

pkill [options] [signal] Process name: terminate a process according to the process name.
Options:

  • -t terminal number: kick out the user according to the terminal number.
  • The pkill command is still very common in actual use. When multiple administrators manage the system at the same time, high-privilege administrators can use the t parameter to kick off low-privilege administrators to prevent their work from being interfered.
  • Example: Use the w command to view the logged-in user, such as tty1, and then use the pkill command "pkill -9 -t tty1" to force the terminal tty1 to be kicked out.

 

Guess you like

Origin www.cnblogs.com/guyuyun/p/12732836.html