进程和端口
Table of Contents
1 进程
1.1 查看当前的内存使用情况
free
usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
-b,-k,-m,-g show output in bytes, KB, MB, or GB -l show detailed low and high memory statistics -o use old format (no -/+buffers/cache line) -t display total for RAM + swap -s update every [delay] seconds -c update [count] times -V display version information and exit
1.2 动态显示进程执行情况
top top指令运行时输入H或?打开帮助窗口,输入Q退出指令。
1.3 查看当前有哪些进程
ps -AFL
1.4 查看进程的启动时间
ps -A -opid,stime,etime,args
1.5 查看当前用户程序实际内存占用,并排序
ps -u $USER -o pid,rss,cmd --sort -rss
1.6 统计程序的内存耗用
ps -eo fname,rss|awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}'|sort -k2 -nr
1.7 按cpu利用率从大到小排列进程
ps -eo "%C : %p : %z : %a"|sort -nr ps aux --sort -pcpu |head -n 20
1.8 查看当前进程树
pstree
1.9 中止一个进程
kill 进程号(就是ps -A中的第一列的数字) 或者 killall 进程名
强制中止一个进程(在上面进程中止不成功的时候使用)
kill -9 进程号 或者 killall -9 进程名
图形方式中止一个程序
xkill 出现骷髅标志的鼠标,点击需要中止的程序即可
1.10 查看进程打开的文件
lsof -p 进程的pid
1.11 显示开启文件abc.txt的进程
lsof abc.txt
1.12 显示22端口现在运行什么程序
lsof -i :22
1.13 显示nsd进程现在打开的文件
lsof -c nsd
1.14 在後台运行程序,退出登录後,并不结束程序
nohup 程序 & #查看中间运行情况 tail nohup
1.15 清除僵尸进程
ps -eal | awk '{ if ($2 == "Z") {print $4}}' | xargs sudo kill -9
2 端口
2.1 查看当前监听80端口的程序
lsof -i 80
2.2 查看当前系统所有的监听端口
nc -zv localhost 1-65535