Linux系统之常用命令
〇、最重要的事儿
- [命令] --help
- man [命令]
环境:CentOS7X64(CentOS Linux release 7.5.1804)
一、CPU相关命令
ps命令
- Tasks:113 total:总进程(任务)数
- 3 running:运行的进程(任务)数,状态码R
- 110 sleeping:睡眠的进程(任务)数,状态码S或D
- 0 stopped:停止的进程(任务)数,状态码T或t
- 0 zombie:僵死的进程(任务)数,状态码Z
按1展示/关闭每个CPU或核的使用率
- 0.8 us:用户空间占用CPU百分比
- 0.0 sy:内核空间占用CPU百分比
- 0.0 ni:用户空间内变更过优先级的进程占用CPU百分比
- 99.2 id:CPU空闲率
- 0.0 wa:等待IO完成的CPU时间百分比
- 0.0 hi:硬中断(Hardware Interrupts)占用的CPU百分比
- 0.0 si:软中断(Software Interrupts)占用的CPU百分比
- 0.0 st:被虚拟机偷走的CPU时间比率
CPU利用率分析,详见:CPU分析。
- 第4部分:内存消耗情况,见free命令
- 第5部分:FIELDS / Columns
- PID:进程Id
- USER:启动进程的用户
- PR:进程优先级
- NI:负数代表高优先级,正数代表低优先级,零表示进程优先级在调度室不会被 调整
- VIRT:进程占用的虚拟内存(Virtual Memory Size (KiB),It includes all code, data and shared libraries plus pages that have been swapped out and pages),对应free命令的swap
- RES:进程占用的物理内存(Resident(固有的) Memory Size (KiB))
- SHR:进程使用的共享内存(Shared Memory Size (KiB)),对应free命令的shared
- S:进程状态,见
- %CPU:CPU使用率
- %MEM:内存使用率
- TIME+:占用CPU的时间
- COMMAND:进程启动命令
命令:
- top
- top -c
- top -Hp
:展示指定进程的子进程
x、查看CPU信息
- 查看物理CPU个数:cat /proc/cpuinfo | grep "physical id" | uniq | wc -l
- 查看每个物理CPU中core的个数(即核数):cat /proc/cpuinfo | grep "cpu cores" | uniq
- 查看逻辑CPU的个数:cat /proc/cpuinfo | grep "processor" | wc -l
二、内存相关命令
pidstat命令
扩展:找出具体文件的读写情况
- lsof -p
命令:iostat -hx 3
分析:详见:I/O分析。
四、网络相关命令
top命令
- r:The number of processes waiting for run time(R状态的进程数量)
- b:The number of processes in uninterruptible sleep(D状态的进程数量)
- swpd:the amount of virtual memory used
- free:the amount of idle memory
- buff:the amount of memory used as buffers
- cache:the amount of memory used as cache
- si:Amount of memory swapped in from disk (/s);
- so:Amount of memory swapped to disk (/s);
- bi:Blocks received from a block device (blocks/s),块设备每秒接收的块数量,简单粗暴地理解为OutputStream;
- bo:Blocks sent to a block device (blocks/s),块设备每秒发送的块数量,简单粗暴地理解为InputStream;
- in:The number of interrupts per second, including the clock;
- cs:The number of context switches per second,每秒上下文切换次数,这个值要越小越好,太大了,要考虑减少线程或者进程的数目,上下文切换次数过多表示CPU大部分浪费在上下文切换,导 致CPU干正经事的时间少了,CPU没有充分利用,不可取;
- us:Time spent running non-kernel code (user time, including nice time),用户CPU时间;
- sy:Time spent running kernel code (system time),系统CPU时间,如果太高,表示系统调用时间长,例如IO操作频繁;
- id:Time spent idle, this includes IO-wait time,空闲 CPU时间,一般来说,id+us+sy=100;
- wa:Time spent waiting for IO, included in idle;
命令:vmstat 1 3
一个w3cschool的Linux教程;