Linux study notes _6: process management and service management

Process management

Written at the beginning:

  1. In Linux, each executed program becomes a process, and each process is assigned an ID number.
  2. Each process corresponds to a parent process, and the parent process can copy multiple child processes.

Process query

ps Commands are used to view the current execution and execution status of those processes in the system.

  • ps -aTo display all the process information of the current terminal
  • ps -uTo display process information in user format
  • ps -xTo display the allowed parameters of the background process

Frequently used instructions:ps-aux | grep [condition]

Instruction list field meaning table:

Field meaning
USER username
PID Process ID number
%CPU The percentage of CPU occupied by the process
%MEM The percentage of physical memory occupied by the process
VSZ The size of virtual memory occupied by the process (KB)
RSS The size of physical memory occupied by the process (KB)
TTY Terminal name, abbreviation
STAT Process s:睡眠state, s:该进程是会话的进程, N:表示进程拥有比普通优先级更低的优先级, R:正在运行, D:短期等待, Z:僵死进程, ,T:被跟踪或被停止
START The start time of the process
TIME CPU time, the total time the process uses the CPU
COMMAND Commands and parameters needed to start the process

View the parent process of the process:, ps -efwhere is PPIDthe process ID number of the parent process

See the process tree: pstree -p/-u, -pdisplay PID of the process, -uthe display belongs to the user process

Terminate the process

  • kill -9 [ID], Forcibly terminate the process, -9to force the thread to terminate.
    • Terminate the remote login (sshd, its CMD is: /usr/sbin/sshd) service:kill [sshdのID]
  • killall [name], Terminate multiple processes (usually used to terminate the parent process with more child processes)

Dynamic process monitoring

topCommands can dynamically query the running status of the process

  • top -d[seconds], Specify the top command to update every few seconds, the default is 3 seconds.
  • top -i, Does not show idle or dead processes.
  • top -p[ID], To monitor the status of the specified process through the specified process ID.

Monitor network status

netstatinstruction

  • netstat -anp | grep serviceNameTo view the network service status of a specific service

Service management (daemon management)

Service Management Directive

  • Service start, stop, status, and reload instructions:service [serviceName] [ start | stop | status | reload ]

It should be noted that after CentOS7, the serviceinstruction is systemctlreplaced by

  • View service name
    • setup -> 系统服务
    • ls -l /etc/init.d/

Service self-starting/shutdown

The self-starting status of each service under different run levels needs to be set

chkconfiginstruction

  • View chkconfig --list | grep serviceNameservices: ,chkconfig serviceName --list
  • Set the automatic startup/shutdown of the service in different run levels:, chkconfig [--level 5(指定规定运行级别,不指定则为所有运行级别下的设置)] serviceName off/onit will reboottake effect after the setting is completed .

Guess you like

Origin blog.csdn.net/Nerver_77/article/details/106933898