Process management
Written at the beginning:
- In Linux, each executed program becomes a process, and each process is assigned an ID number.
- 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 -a
To display all the process information of the current terminalps -u
To display process information in user formatps -x
To 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 -ef
where is PPID
the process ID number of the parent process
See the process tree: pstree -p/-u
, -p
display PID of the process, -u
the display belongs to the user process
Terminate the process
kill -9 [ID]
, Forcibly terminate the process,-9
to force the thread to terminate.- Terminate the remote login (sshd, its CMD is: /usr/sbin/sshd) service:
kill [sshdのID]
- Terminate the remote login (sshd, its CMD is: /usr/sbin/sshd) service:
killall [name]
, Terminate multiple processes (usually used to terminate the parent process with more child processes)
Dynamic process monitoring
top
Commands 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
netstat
instruction
netstat -anp | grep serviceName
To 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 service
instruction is systemctl
replaced 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
chkconfig
instruction
- View
chkconfig --list | grep serviceName
services: ,chkconfig serviceName --list
- Set the automatic startup/shutdown of the service in different run levels:,
chkconfig [--level 5(指定规定运行级别,不指定则为所有运行级别下的设置)] serviceName off/on
it willreboot
take effect after the setting is completed .