1.
vmstat工具,可以查看系統級別的負載情況,包括進程、內存、IO、CPU、系統調用等等
用法:vmstat [options] [delay [count]]
第一行是自上次reboot之后的平均負載,之后的輸出是該delay時間段內的增量值(比如中斷數、系統調用數等,但像是內存、cpu負載這些參數等就還是實時值)
輸出示例:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 0 8 266056 130176 1352704 0 0 294 35 665 1552 8 4 86 2 0
1 0 8 264356 130216 1354632 0 0 0 184 1958 2605 1 4 93 2 0
0 0 8 264248 130216 1354660 0 0 0 0 781 1364 1 1 99 0 0
參數解釋:
Procs
r: The number of runnable processes (running or waiting for run time).
b: The number of processes in uninterruptible sleep.
Memory
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.
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)
Swap
si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).
IO
bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).
System
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.
CPU
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
2.
使用ps命令列出cpu使用率最高的幾個進程:
ps -eo pid,user,pcpu,command --sort=-pcpu | head -n 10
3.
查看進程的線程和線程占用的資源:
ps -Lp 1567284
top -H -p 1567284
4.
查看進程打開了哪些文件、套接字、設備、目錄等:
lsof -n -p 403601 參數-n是不進行dns解析,-p指示進程號
5.
int ioctl(int fd, ind cmd, …)參數:
fd是用戶程序打開設備時使用open函數返回的文件標示符,cmd是用戶程序對設備的控制命令,至於后面的省略號,那是一些補充參數,一般最多一個,這個參數的有無和cmd的意義相關
6.
查cpu的中斷數:
cat /proc/interrupts | awk '{print $25,$22,$29,$50}'
參考:
https://www.ibm.com/developerworks/community/blogs/aimsupport/entry/investigating_high_cpu_for_java_processes_on_linux_aix_hpux_solaris_windows_identifying_the_suspects?lang=en
https://www.tecmint.com/strace-commands-for-troubleshooting-and-debugging-linux/
https://www.howtoforge.com/linux-strace-command/