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 僵尸进程;
root@iZuf6c0rnhno78oq2pxylnZ:~# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
·
·
·
root@iZuf6c0rnhno78oq2pxylnZ:~# kill -l KILL
9
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、杀死nginx进程:kill -9 323 30902
root@iZuf6c0rnhno78oq2pxylnZ:~# kill -9 323 30902
ps:lsof -i 需要 root 用户的权限来执行
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)
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)
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)
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
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
每天一个linux命令(42):kill命
Linux 查看端口占用情况
Linux命令大全
如何在 Linux 中查看进程占用的端口号
原文:https://www.cnblogs.com/snailrunning/p/12180657.html