View system processes
- ps: the current process for reporting system status
- a: the display program execution in all of the terminal
ps -ef/ps aux: 这两个命令都是查看当前系统正在运行进程,两者的区别是展示格式不同。
如果想要查看特定的进程可以使用这样的格式:ps aux|grep redis (查看包括redis字符串的进程)
[root@VM_0_4_centos ~]# ps -ef | grep nginx
root 1892 1 0 15:19 ? 00:00:00 nginx: master process nginx
nginx 1893 1892 0 15:19 ? 00:00:00 nginx: worker process
root 1908 1248 0 15:19 pts/0 00:00:00 grep --color=auto nginx
root@iZuf6c0rnhno78oq2pxylnZ:~# ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
USER 进程的属主;
PID 进程的ID;
PPID 父进程;
%CPU 进程占用的CPU百分比;
%MEM 占用内存的百分比;
NI 进程的NICE值,数值大,表示较少占用CPU时间;
VSZ 进程虚拟大小;
RSS 驻留中页的数量;
TTY 终端ID
STAT 进程状态(有以下几种)
D 无法中断的休眠状态(通常 IO 的进程);
R 正在运行可中在队列中可过行的;
S 处于休眠状态;
T 停止或被追踪;
W 进入内存交换(从内核2.6开始无效);
X 死掉的进程(从来没见过);
Z 僵尸进程;
Kill the process
- kill: to delete the program or work execution
- Syntax: kill (Option) (parameters)
- Options:
- a: When dealing with the current process, does not limit the correspondence between the command name and the process ID;
- l <message number>: If left <message number> option, the -l option will list the names of all of the information;
- p: Specifies the kill command to print only the process ID related processes, without sending any signal;
- s <message name or number>: Specifies the information sent;
- u: Specifies the user
- a: When dealing with the current process, does not limit the correspondence between the command name and the process ID;
- Parameters: process or job ID: Specifies the process or job to be deleted. Common PID
- List all signal names
- kill -l
root@iZuf6c0rnhno78oq2pxylnZ:~# kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 · · ·
- Numerical designation signal obtained
- kill -l KILL
root@iZuf6c0rnhno78oq2pxylnZ:~# kill -l KILL 9
- Kill the process
- View nginx processes: ps -aux | grep nginx
root@iZuf6c0rnhno78oq2pxylnZ:~# ps -aux | grep nginx
root 323 0.0 0.2 117656 4924 ? Ss 2019 0:00 nginx: master process nginx
root 3412 0.0 0.0 14224 968 pts/0 S+ 16:32 0:00 grep --color=auto nginx
www-data 30902 0.0 0.2 118032 4992 ? S Jan04 0:00 nginx: worker process
2, killing nginx processes: kill -9 323 30902
root@iZuf6c0rnhno78oq2pxylnZ:~# kill -9 323 30902
Viewer occupied port number
ps: lsof -i requires root permissions to perform
- lsof: the current system is a tool list of open files
- Syntax: lsof (option)
- Options
- a: list the process of opening an existing file;
- c <process name>: lists the specified process open files;
- g: GID list number of the process details;
- d <file number>: Lists the occupation process the file number;
- d <directory>: List directory files from being opened;
- D <directory>: recursively list directory files from being opened;
- n <directory>: List of files using NFS;
- i <condition>: Lists qualifying process. (4,6, agreement: port, @ip)
- p <process ID>: List the process is specified as open files;
- u: UID number listed details of the process;
- h: display help information;
- v: Displays version information.
- Check occupied port 80 program
- lsof -i: port number
root@iZuf6c0rnhno78oq2pxylnZ:~# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
AliYunDun 822 root 21u IPv4 46829108 0t0 TCP 172.17.1.142:37126->100.100.30.25:http (ESTABLISHED)
nginx 19170 root 6u IPv4 69865848 0t0 TCP 172.17.1.142:http (LISTEN)
nginx 19173 www-data 6u IPv4 69865848 0t0 TCP 172.17.1.142:http (LISTEN)
- Check occupied by the process according to the port number PID
- lsof -i | grep pid
root@iZuf6c0rnhno78oq2pxylnZ:~# lsof -i | grep 19170
nginx 19170 root 6u IPv4 69865848 0t0 TCP 172.17.1.142:http (LISTEN)
nginx 19170 root 7u IPv4 69865849 0t0 TCP 172.17.1.142:81 (LISTEN)
nginx 19170 root 8u IPv4 69865850 0t0 TCP 172.17.1.142:8000 (LISTEN)
nginx 19170 root 9u IPv4 69865851 0t0 TCP 172.17.1.142:8001 (LISTEN)
nginx 19170 root 10u IPv4 69865852 0t0 TCP 172.17.1.142:8002 (LISTEN)
- According to the process name to view the port number occupied
root@iZuf6c0rnhno78oq2pxylnZ:~# lsof -i | grep nginx
nginx 19170 root 6u IPv4 69865848 0t0 TCP 172.17.1.142:http (LISTEN)
nginx 19170 root 7u IPv4 69865849 0t0 TCP 172.17.1.142:81 (LISTEN)
nginx 19170 root 8u IPv4 69865850 0t0 TCP 172.17.1.142:8000 (LISTEN)
nginx 19170 root 9u IPv4 69865851 0t0 TCP 172.17.1.142:8001 (LISTEN)
nginx 19170 root 10u IPv4 69865852 0t0 TCP 172.17.1.142:8002 (LISTEN)
nginx 19173 www-data 6u IPv4 69865848 0t0 TCP 172.17.1.142:http (LISTEN)
nginx 19173 www-data 7u IPv4 69865849 0t0 TCP 172.17.1.142:81 (LISTEN)
nginx 19173 www-data 8u IPv4 69865850 0t0 TCP 172.17.1.142:8000 (LISTEN)
nginx 19173 www-data 9u IPv4 69865851 0t0 TCP 172.17.1.142:8001 (LISTEN)
nginx 19173 www-data 10u IPv4 69865852 0t0 TCP 172.17.1.142:8002 (LISTEN)
View Linux network system status information
- netstat
- Syntax: netstat (option)
- Options:
- or a --all: all wiring in the Socket;
- n or --numeric: ip address directly, without passing through the domain name server;
- p or --programs: display program identifier and the program name being used Socket;
- According to the process name to view the port number occupied
root@iZuf6c0rnhno78oq2pxylnZ:~# netstat -anp | grep nginx
tcp 0 0 172.17.1.142:8000 0.0.0.0:* LISTEN 19170/nginx: master
tcp 0 0 172.17.1.142:8001 0.0.0.0:* LISTEN 19170/nginx: master
tcp 0 0 172.17.1.142:8002 0.0.0.0:* LISTEN 19170/nginx: master
tcp 0 0 172.17.1.142:80 0.0.0.0:* LISTEN 19170/nginx: master
tcp 0 0 172.17.1.142:81 0.0.0.0:* LISTEN 19170/nginx: master
unix 3 [ ] STREAM CONNECTED 69865863 19170/nginx: master
unix 3 [ ] STREAM CONNECTED 69865862 19170/nginx: master
- Check occupied by the process according to the port number PID
root@iZuf6c0rnhno78oq2pxylnZ:~# netstat -anp | grep 80
tcp 0 0 172.17.1.142:8000 0.0.0.0:* LISTEN 19170/nginx: master
tcp 0 0 172.17.1.142:8001 0.0.0.0:* LISTEN 19170/nginx: master
tcp 0 0 172.17.1.142:8002 0.0.0.0:* LISTEN 19170/nginx: master
tcp 0 0 172.17.1.142:80 0.0.0.0:* LISTEN 19170/nginx: master
Reference article
Every day a linux command (42): kill command
Linux view the port occupancy
Linux command Daquan
how to view the process of occupation in Linux port number