Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux进程命令篇 #39

Open
gnipbao opened this issue Jul 13, 2020 · 0 comments
Open

Linux进程命令篇 #39

gnipbao opened this issue Jul 13, 2020 · 0 comments
Labels

Comments

@gnipbao
Copy link
Owner

gnipbao commented Jul 13, 2020

lsof 列出当前系统打开文件

查看指定端口号语法格式:lsof -i:端口号
如果命令找不到 yum install lsof -y

[root@localhost ~]# lsof -i:7075
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 17394 root    4u  IPv6  75775      0t0  TCP *:7075 (LISTEN)

查看所有端口占用: lsof -i

[root@vultr ~]# lsof -i
COMMAND    PID    USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
chronyd    421  chrony    5u  IPv4   15794      0t0  UDP localhost:323 
chronyd    421  chrony    6u  IPv6   15795      0t0  UDP localhost:323 
dhclient   759    root    6u  IPv4   16886      0t0  UDP *:bootpc 
sshd       822    root    3u  IPv4   18590      0t0  TCP *:ssh (LISTEN)
sshd       822    root    4u  IPv6   18599      0t0  TCP *:ssh (LISTEN)
python     984    root    4u  IPv6   19154      0t0  TCP *:cbt (LISTEN)
python     984    root    6u  IPv6   19155      0t0  UDP *:cbt 
python     984    root    9u  IPv4   19174      0t0  UDP *:37738 

netstat

用于显示 tcp,udp 的端口和进程等相关情况:netstat -tunlp
netstat 查看端口占用语法格式:netstat -tunlp | grep 端口号

  • -t (tcp) 仅显示tcp相关选项
  • -u (udp)仅显示udp相关选项
  • -n 拒绝显示别名,能显示数字的全部转化为数字
  • -l 仅列出在Listen(监听)的服务状态
  • -p 显示建立相关链接的程序名
[root@localhost ~]# netstat -tunlp | grep 7075
tcp6       0      0 :::7075                 :::*                    LISTEN      17394/docker-proxy  
[root@localhost ~]# 
[root@localhost ~]# netstat -tunlp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      19356/mysqld        
[root@localhost ~]# 
[root@localhost ~]# netstat -tunlp | grep 1521
tcp6       0      0 :::1521                 :::*                    LISTEN      17470/docker-proxy  
[root@localhost ~]# 
[root@localhost ~]# netstat -tunlp | grep 1525
[root@localhost ~]# 
[root@localhost ~]# netstat -tunlp | grep 1522
tcp6       0      0 :::1522                 :::*                    LISTEN      17436/docker-proxy  
[root@localhost ~]#

ps 显示当前进程状态

显示本用户的进程:ps

[root@localhost ~]# ps
  PID TTY          TIME CMD
30059 pts/0    00:00:00 bash
31149 pts/0    00:00:00 ps

显示所有用户进程:ps aux
显示指定进程和其状态:ps -aux | grep 服务

[root@localhost ~]# ps -aux | grep httpd
root     31122  0.0  0.0 112680   696 pts/0    S+   14:01   0:00 grep --color=auto httpd
[root@localhost ~]# 
[root@localhost ~]# ps -aux | grep vsftpd
root     31124  0.0  0.0 112680   696 pts/0    S+   14:01   0:00 grep --color=auto vsftpd

kill

终止进程:kill -9 [PID]

@gnipbao gnipbao added the Linux label Jul 13, 2020
@gnipbao gnipbao changed the title Linux网络进程篇 Linux进程命令篇 Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant