{"id":262,"date":"2022-06-02T16:08:43","date_gmt":"2022-06-02T08:08:43","guid":{"rendered":"https:\/\/frogvps.com\/?p=262"},"modified":"2022-06-02T16:08:43","modified_gmt":"2022-06-02T08:08:43","slug":"linux%e6%9f%a5%e7%9c%8b%e8%bf%9b%e7%a8%8b%e5%91%bd%e4%bb%a4%e6%b1%87%e6%80%bb","status":"publish","type":"post","link":"https:\/\/frogvps.com\/?p=262","title":{"rendered":"linux\u67e5\u770b\u8fdb\u7a0b\u547d\u4ee4\u6c47\u603b"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"769\" src=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a1-1024x769.jpg\" alt=\"\" class=\"wp-image-263\" srcset=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a1-1024x769.jpg 1024w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a1-300x225.jpg 300w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a1-768x576.jpg 768w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a1-1536x1153.jpg 1536w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a1-2048x1537.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u672c\u6587\u603b\u7ed3\u4e86\u5927\u90e8\u5206\u5e38\u7528\u7684linux\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8fdb\u7a0b\u6811 pstree<\/h2>\n\n\n\n<p>pstree \u53ef\u4ee5\u7528\u6765\u663e\u793a\u8fdb\u7a0b\u7684\u7236\u5b50\u5173\u7cfb\uff0c\u4ee5\u6811\u5f62\u7ed3\u6784\u663e\u793a\u3002<\/p>\n\n\n\n<p>\u683c\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pstree &#91;OPTION] &#91; PID | USER ]<\/code><\/pre>\n\n\n\n<p>\u5e38\u7528\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-p \u663e\u793aPID\n-T \u4e0d\u663e\u793a\u7ebf\u7a0bthread,\u9ed8\u8ba4\u663e\u793a\u7ebf\u7a0b\n-u \u663e\u793a\u7528\u6237\u5207\u6362\n-H pid \u9ad8\u4eae\u663e\u793a\u6307\u5b9a\u8fdb\u7a0b\u53ca\u5176\u524d\u8f88\u8fdb\u7a0b<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u8fdb\u7a0b\u4fe1\u606f ps<\/h2>\n\n\n\n<p>ps \u5373 process state\uff0c\u53ef\u4ee5\u8fdb\u7a0b\u5f53\u524d\u72b6\u6001\u7684\u5feb\u7167\uff0c\u9ed8\u8ba4\u663e\u793a\u5f53\u524d\u7ec8\u7aef\u4e2d\u7684\u8fdb\u7a0b\uff0cLinux\u7cfb\u7edf\u5404\u8fdb\u7a0b\u7684\u76f8<br>\u5173\u4fe1\u606f\u5747\u4fdd\u5b58\u5728\/proc\/PID\u76ee\u5f55\u4e0b\u7684\u5404\u6587\u4ef6\u4e2d\u3002<\/p>\n\n\n\n<p>ps\u683c\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps &#91;OPTION]...<\/code><\/pre>\n\n\n\n<p>\u652f\u6301\u4e09\u79cd\u9009\u9879\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>UNIX\u9009\u9879 \u5982: -A -e<\/li><li>GNU\u9009\u9879 \u5982: &#8211;help<\/li><li>BSD\u9009\u9879 \u5982: a<\/li><\/ul>\n\n\n\n<p>\u5e38\u7528\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a \u9009\u9879\u5305\u62ec\u6240\u6709\u7ec8\u7aef\u4e2d\u7684\u8fdb\u7a0b\nx \u9009\u9879\u5305\u62ec\u4e0d\u94fe\u63a5\u7ec8\u7aef\u7684\u8fdb\u7a0b\nu \u9009\u9879\u663e\u793a\u8fdb\u7a0b\u6240\u6709\u8005\u7684\u4fe1\u606f\nf \u9009\u9879\u663e\u793a\u8fdb\u7a0b\u6811,\u76f8\u5f53\u4e8e --forest\nk|--sort \u5c5e\u6027 \u5bf9\u5c5e\u6027\u6392\u5e8f,\u5c5e\u6027\u524d\u52a0 - \u8868\u793a\u5012\u5e8f\no \u5c5e\u6027\u2026 \u9009\u9879\u663e\u793a\u5b9a\u5236\u7684\u4fe1\u606f pid\u3001cmd\u3001%cpu\u3001%mem\nL \u663e\u793a\u652f\u6301\u7684\u5c5e\u6027\u5217\u8868\n-C cmdlist \u6307\u5b9a\u547d\u4ee4\uff0c\u591a\u4e2a\u547d\u4ee4\u7528\uff0c\u5206\u9694\n-L \u663e\u793a\u7ebf\u7a0b\n-e \u663e\u793a\u6240\u6709\u8fdb\u7a0b\uff0c\u76f8\u5f53\u4e8e-A\n-f \u663e\u793a\u5b8c\u6574\u683c\u5f0f\u7a0b\u5e8f\u4fe1\u606f\n-F \u663e\u793a\u66f4\u5b8c\u6574\u683c\u5f0f\u7684\u8fdb\u7a0b\u4fe1\u606f\n-H \u4ee5\u8fdb\u7a0b\u5c42\u7ea7\u683c\u5f0f\u663e\u793a\u8fdb\u7a0b\u76f8\u5173\u4fe1\u606f\n-u userlist \u6307\u5b9a\u6709\u6548\u7684\u7528\u6237ID\u6216\u540d\u79f0\n-U userlist \u6307\u5b9a\u771f\u6b63\u7684\u7528\u6237ID\u6216\u540d\u79f0\n-g gid\u6216groupname \u6307\u5b9a\u6709\u6548\u7684gid\u6216\u7ec4\u540d\u79f0\n-G gid\u6216groupname \u6307\u5b9a\u771f\u6b63\u7684gid\u6216\u7ec4\u540d\u79f0\n-p pid \u663e\u793a\u6307pid\u7684\u8fdb\u7a0b\n--ppid pid \u663e\u793a\u5c5e\u4e8epid\u7684\u5b50\u8fdb\u7a0b\n-t ttylist \u6307\u5b9atty,\u76f8\u5f53\u4e8e t\n-M \u663e\u793aSELinux\u4fe1\u606f\uff0c\u76f8\u5f53\u4e8eZ<\/code><\/pre>\n\n\n\n<p>ps \u8f93\u51fa\u5c5e\u6027\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C : ps -ef \u663e\u793a\u5217 C \u8868\u793acpu\u5229\u7528\u7387\nVSZ: Virtual memory SiZe\uff0c\u865a\u62df\u5185\u5b58\u96c6\uff0c\u7ebf\u6027\u5185\u5b58\nRSS: ReSident Size, \u5e38\u9a7b\u5185\u5b58\u96c6\nSTAT\uff1a\u8fdb\u7a0b\u72b6\u6001\nR\uff1arunning\nS: interruptable sleeping\nD: uninterruptable sleeping\nT: stopped\nZ: zombie\n+: \u524d\u53f0\u8fdb\u7a0b\nl: \u591a\u7ebf\u7a0b\u8fdb\u7a0b\nL\uff1a\u5185\u5b58\u5206\u9875\u5e76\u5e26\u9501\nN\uff1a\u4f4e\u4f18\u5148\u7ea7\u8fdb\u7a0b\n&lt;: \u9ad8\u4f18\u5148\u7ea7\u8fdb\u7a0b\ns: session leader\uff0c\u4f1a\u8bdd\uff08\u5b50\u8fdb\u7a0b\uff09\u53d1\u8d77\u8005\nI\uff1aIdle kernel thread\uff0cCentOS 8 \u65b0\u7279\u6027\nni: nice\u503c\npri: priority \u4f18\u5148\u7ea7\nrtprio: \u5b9e\u65f6\u4f18\u5148\u7ea7\npsr: processor CPU\u7f16\u53f7<\/code><\/pre>\n\n\n\n<p>\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps axo pid,cmd,psr,ni,pri,rtprio<\/code><\/pre>\n\n\n\n<p>\u5e38\u7528\u7ec4\u5408\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aux\n-ef\n-eFH\n-eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,comm\naxo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a\u67e5\u770b\u8fdb\u7a0b\u8be6\u7ec6\u4fe1\u606f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5217 C \u8868\u793a CPU\u5229\u7528\u7387\nps -ef\nps aux\n#\u67e5\u770b\u8fdb\u7a0b\u7684\u7236\u5b50\u5173\u7cfb\nps auxf\n#\u67e5\u770b\u8fdb\u7a0b\u7684\u7279\u5b9a\u5c5e\u6027\nps axo pid,cmd,%mem,%cpu\n#\u6309CPU\u5229\u7528\u7387\u5012\u5e8f\u6392\u5e8f\nps aux k -%cpu\nps axo pid,cmd,%cpu,%mem k -%cpu\n#\u6309\u5185\u5b58\u6392\u5e8f\nps axo pid,cmd,%cpu,%mem --sort %mem<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u67e5\u8be2\u4f60\u62e5\u6709\u7684\u6240\u6709\u8fdb\u7a0b\nps -x\n#\u663e\u793a\u6307\u5b9a\u7528\u6237\u540d(RUID)\u6216\u7528\u6237ID\u7684\u8fdb\u7a0b\nps -fU apache\nps -fU 48\n#\u663e\u793a\u6307\u5b9a\u7528\u6237\u540d(EUID)\u6216\u7528\u6237ID\u7684\u8fdb\u7a0b\nps -fu frog\nps -fu 1000\n#\u67e5\u770b\u4ee5root\u7528\u6237\u6743\u9650\uff08\u5b9e\u9645\u548c\u6709\u6548ID\uff09\u8fd0\u884c\u7684\u6bcf\u4e2a\u8fdb\u7a0b\nps -U root -u root\nps -U root -u root\n#\u5217\u51fa\u67d0\u4e2a\u7ec4\u62e5\u6709\u7684\u6240\u6709\u8fdb\u7a0b\uff08\u5b9e\u9645\u7ec4ID\uff1aRGID\u6216\u540d\u79f0\uff09\nps -fG nginx\n#\u5217\u51fa\u6709\u6548\u7ec4\u540d\u79f0\uff08\u6216\u4f1a\u8bdd\uff09\u6240\u62e5\u6709\u7684\u6240\u6709\u8fdb\u7a0b\nps -fg mysql\nps -fg 27\n#\u663e\u793a\u6307\u5b9a\u7684\u8fdb\u7a0bID\u5bf9\u5e94\u7684\u8fdb\u7a0b\nps -fp 1234\n#\u4ee5\u7236\u8fdb\u7a0bID\u6765\u663e\u793a\u5176\u4e0b\u6240\u6709\u7684\u8fdb\u7a0b\uff0c\u5982\u663e\u793a\u7236\u8fdb\u7a0b\u4e3a1234\u7684\u6240\u6709\u8fdb\u7a0b\nps -f --ppid 1234\n#\u663e\u793a\u6307\u5b9aPID\u7684\u591a\u4e2a\u8fdb\u7a0b\nps -fp 1204,1239,1263\n#\u8981\u6309tty\u663e\u793a\u6240\u5c5e\u8fdb\u7a0b\nps -ft pts\/0\n#\u4ee5\u8fdb\u7a0b\u6811\u663e\u793a\u7cfb\u7edf\u4e2d\u7684\u8fdb\u7a0b\u5982\u4f55\u76f8\u4e92\u94fe\u63a5\nps -e --forest\n#\u4ee5\u8fdb\u7a0b\u6811\u663e\u793a\u6307\u5b9a\u7684\u8fdb\u7a0b\nps -f --forest -C sshd\nps -ef --forest | grep -v grep | grep sshd\n#\u8981\u663e\u793a\u4e00\u4e2a\u8fdb\u7a0b\u7684\u6240\u6709\u7ebf\u7a0b,\u5c06\u663e\u793aLWP\uff08\u8f7b\u91cf\u7ea7\u8fdb\u7a0b\uff09\u4ee5\u53caNLWP\uff08\u8f7b\u91cf\u7ea7\u8fdb\u7a0b\u6570\uff09\u5217\nps -fL -C nginx\n#\u8981\u5217\u51fa\u6240\u6709\u683c\u5f0f\u8bf4\u660e\u7b26\nps L\n#\u67e5\u770b\u8fdb\u7a0b\u7684PID\uff0cPPID\uff0c\u7528\u6237\u540d\u548c\u547d\u4ee4\nps -eo pid,ppid,user,cmd\n#\u81ea\u5b9a\u4e49\u683c\u5f0f\u663e\u793a\u6587\u4ef6\u7cfb\u7edf\u7ec4,ni\u503c\u5f00\u59cb\u65f6\u95f4\u548c\u8fdb\u7a0b\u7684\u65f6\u95f4\nps -p 1234 -o pid,ppid,fgroup,ni,lstart,etime\n#\u4f7f\u7528\u5176PID\u67e5\u627e\u8fdb\u7a0b\u540d\u79f0\uff1a\nps -p 1244 -o comm=\n#\u8981\u4ee5\u5176\u540d\u79f0\u9009\u62e9\u7279\u5b9a\u8fdb\u7a0b\uff0c\u663e\u793a\u5176\u6240\u6709\u5b50\u8fdb\u7a0b\nps -C sshd,bash\n#\u67e5\u627e\u6307\u5b9a\u8fdb\u7a0b\u540d\u6240\u6709\u7684\u6240\u5c5ePID\uff0c\u5728\u7f16\u5199\u9700\u8981\u4ecestd\u8f93\u51fa\u6216\u6587\u4ef6\u8bfb\u53d6PID\u7684\u811a\u672c\u65f6\u8fd9\u4e2a\u53c2\u6570\u5f88\u6709\u7528\nps -C httpd,sshd -o pid=\n#\u68c0\u67e5\u4e00\u4e2a\u8fdb\u7a0b\u7684\u6267\u884c\u65f6\u95f4\nps -eo comm,etime,user | grep nginx\n#\u6392\u5e8f\uff0c\u67e5\u627e\u5360\u7528\u6700\u591a\u5185\u5b58\u548cCPU\u7684\u8fdb\u7a0b\nps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head\nps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head\n#\u663e\u793a\u5b89\u5168\u4fe1\u606f\nps -eM\nps --context\n#\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u7528\u6237\u5b9a\u4e49\u7684\u683c\u5f0f\u663e\u793a\u5b89\u5168\u4fe1\u606f\nps -eo euser,ruser,suser,fuser,f,comm,label\n#\u4f7f\u7528watch\u5b9e\u7528\u7a0b\u5e8f\u6267\u884c\u91cd\u590d\u7684\u8f93\u51fa\u4ee5\u5b9e\u73b0\u5bf9\u5c31\u7a0b\u8fdb\u884c\u5b9e\u65f6\u7684\u76d1\u89c6\uff0c\u5982\u4e0b\u9762\u7684\u547d\u4ee4\u663e\u793a\u6bcf\u79d2\u949f\u7684\u76d1\u89c6\nwatch -n 1 'ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head'<\/code><\/pre>\n\n\n\n<p>\u627e\u5230\u672a\u77e5\u8fdb\u7a0b\u7684\u6267\u884c\u7a0b\u5e8f\u6587\u4ef6\u8def\u5f84<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -l \/proc\/PID\/exe<\/code><\/pre>\n\n\n\n<p>\u67e5\u770b\u4f18\u5148\u7ea7\u548cCPU\u7ed1\u5b9a\u5173\u7cfb<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps axo pid,cmd,ni,pri,psr,rtprio<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f prtstat<\/h2>\n\n\n\n<p>\u53ef\u4ee5\u663e\u793a\u8fdb\u7a0b\u4fe1\u606f,\u6765\u81ea\u4e8epsmisc\u5305\u3002<\/p>\n\n\n\n<p>\u683c\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>prtstat &#91;options] PID ...<\/code><\/pre>\n\n\n\n<p>\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-r raw \u683c\u5f0f\u663e\u793a<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@DMIT-iJboSKPbP4:~# prtstat 1\nProcess: systemd               State: S (sleeping)\n  CPU#:  0          TTY: 0:0    Threads: 1\nProcess, Group and Session IDs\n  Process ID: 1          Parent ID: 0\n    Group ID: 1         Session ID: 1\n  T Group ID: -1\n\nPage Faults\n  This Process    (minor major):   316326    100626\n  Child Processes (minor major): 19215632   8474730\nCPU Times\n  This Process    (user system guest blkio):  33.29  31.04   0.00  43.79\n  Child processes (user system guest):       1203.97 1344.32   0.00\nMemory\n  Vsize:       172 MB    \n  RSS:         10 MB               RSS Limit: 18446744073709 MB\n  Code Start:  0x562c1717b000         Code Stop:  0x562c1726ae65\n  Stack Start: 0x7ffec64e7e90\n  Stack Pointer (ESP):          0     Inst Pointer (EIP):          0\nScheduling\n  Policy: normal\n  Nice:   0          RT Priority: 0 (non RT)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u641c\u7d22\u8fdb\u7a0b<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>ps \u9009\u9879 | grep &#8216;pattern&#8217; \u7075\u6d3b<\/li><li>pgrep \u6309\u9884\u5b9a\u4e49\u7684\u6a21\u5f0f<\/li><li>\/sbin\/pidof \u6309\u786e\u5207\u7684\u7a0b\u5e8f\u540d\u79f0\u67e5\u770bpid<\/li><\/ul>\n\n\n\n<p><strong>pgrep<\/strong><\/p>\n\n\n\n<p>\u547d\u4ee4\u683c\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pgrep &#91;options] pattern<\/code><\/pre>\n\n\n\n<p>\u5e38\u7528\u9009\u9879<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-u uid: effective user\uff0c\u751f\u6548\u8005\n-U uid: real user\uff0c\u771f\u6b63\u53d1\u8d77\u8fd0\u884c\u547d\u4ee4\u8005\n-t terminal: \u4e0e\u6307\u5b9a\u7ec8\u7aef\u76f8\u5173\u7684\u8fdb\u7a0b\n-l: \u663e\u793a\u8fdb\u7a0b\u540d\n-a: \u663e\u793a\u5b8c\u6574\u683c\u5f0f\u7684\u8fdb\u7a0b\u540d\n-P pid: \u663e\u793a\u6307\u5b9a\u8fdb\u7a0b\u7684\u5b50\u8fdb\u7a0b<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@DMIT-iJboSKPbP4:~# pgrep -u nginx\n757\n\nroot@DMIT-iJboSKPbP4:~# pgrep -lu nginx\n757 nginx\n\nroot@DMIT-iJboSKPbP4:~# pgrep -lau nginx\n757 nginx: worker process \n\nroot@DMIT-iJboSKPbP4:~# pgrep -aP 753\n757 nginx: worker process \n\nroot@DMIT-iJboSKPbP4:~# pgrep -at pts\/1\n93994 -bash<\/code><\/pre>\n\n\n\n<p><strong>pidof<\/strong><\/p>\n\n\n\n<p>\u547d\u4ee4\u683c\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pidof &#91;options] &#91;program &#91;...]]<\/code><\/pre>\n\n\n\n<p>\u5e38\u7528\u9009\u9879<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-x \u6309\u811a\u672c\u540d\u79f0\u67e5\u627epid,\u811a\u672c\u7528\u8def\u5f84\u6267\u884c\u4e14\u6709shebang\u673a\u5236\u624d\u80fd\u88ab\u627e\u5230<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@DMIT-iJboSKPbP4:~# pidof bash\n93994 93784<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u8d1f\u8f7d\u67e5\u8be2 uptime<\/h2>\n\n\n\n<p>\/proc\/uptime \u5305\u62ec\u4e24\u4e2a\u503c\uff0c\u5355\u4f4d s<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u7cfb\u7edf\u542f\u52a8\u65f6\u957f<\/li><li>\u7a7a\u95f4\u8fdb\u7a0b\u7684\u603b\u65f6\u957f<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>root@DMIT-iJboSKPbP4:~# cat \/proc\/uptime\n1099626.97 1091624.04<\/code><\/pre>\n\n\n\n<p>uptime \u548c w \u663e\u793a\u4ee5\u4e0b\u5185\u5bb9<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5f53\u524d\u65f6\u95f4<\/li><li>\u7cfb\u7edf\u5df2\u542f\u52a8\u65f6\u95f4<\/li><li>\u5f53\u524d\u4e0a\u7ebf\u4eba\u6570<\/li><li>\u7cfb\u7edf\u5e73\u5747\u8d1f\u8f7d\uff081\u30015\u300115\u5206\u949f\u7684\u5e73\u5747\u8d1f\u8f7d\uff0c\u4e00\u822c\u4e0d\u4f1a\u8d85\u8fc71\uff0c\u8d85\u8fc75\u65f6\u5efa\u8bae\u8b66\u62a5\uff09<\/li><\/ul>\n\n\n\n<p>\u7cfb\u7edf\u5e73\u5747\u8d1f\u8f7d:<\/p>\n\n\n\n<p>\u6307\u5728\u7279\u5b9a\u65f6\u95f4\u95f4\u9694\u5185\u8fd0\u884c\u961f\u5217\u4e2d\u7684\u5e73\u5747\u8fdb\u7a0b\u6570,\u901a\u5e38\u6bcf\u4e2aCPU\u5185\u6838\u7684\u5f53\u524d\u6d3b\u52a8\u8fdb\u7a0b\u6570\u4e0d\u5927\u4e8e3\uff0c\u90a3\u4e48\u7cfb\u7edf\u7684\u6027\u80fd\u826f\u597d\u3002\u5982\u679c\u6bcf\u4e2aCPU\u5185\u6838\u7684\u4efb\u52a1\u6570\u5927\u4e8e5\uff0c\u90a3\u4e48\u6b64\u4e3b\u673a\u7684\u6027\u80fd\u6709\u4e25\u91cd\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6709\u4e00\u53f0\u670d\u52a1\u5668\u662f1\u4e2a\u53cc\u6838CPU\uff0c\u5f53Load Average \u4e3a6\u7684\u65f6\u5019\u8bf4\u660e\u673a\u5668\u5df2\u7ecf\u88ab\u5145\u5206\u4f7f\u7528\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u67e5\u770b\u8fdb\u7a0b\u5b9e\u65f6\u72b6\u6001 top \u548c htop<\/h2>\n\n\n\n<p><strong>top<\/strong><\/p>\n\n\n\n<p>top \u63d0\u4f9b\u52a8\u6001\u7684\u5b9e\u65f6\u8fdb\u7a0b\u72b6\u6001<\/p>\n\n\n\n<p>\u5185\u7f6e\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5e2e\u52a9\uff1ah \u6216 \uff1f \uff0c\u6309 q \u6216esc \u9000\u51fa\u5e2e\u52a9\n\n\u6392\u5e8f\uff1a\nP\uff1a\u4ee5\u5360\u636e\u7684CPU\u767e\u5206\u6bd4,%CPU\nM\uff1a\u5360\u636e\u5185\u5b58\u767e\u5206\u6bd4,%MEM\nT\uff1a\u7d2f\u79ef\u5360\u636eCPU\u65f6\u957f,TIME+\n\n\u9996\u90e8\u4fe1\u606f\u663e\u793a\uff1a\nuptime\u4fe1\u606f\uff1al\u547d\u4ee4\ntasks\u53cacpu\u4fe1\u606f\uff1at\u547d\u4ee4\ncpu\u5206\u522b\u663e\u793a\uff1a1 (\u6570\u5b57)\nmemory\u4fe1\u606f\uff1am\u547d\u4ee4\n\u9000\u51fa\u547d\u4ee4\uff1aq\n\u4fee\u6539\u5237\u65b0\u65f6\u95f4\u95f4\u9694\uff1as\n\u7ec8\u6b62\u6307\u5b9a\u8fdb\u7a0b\uff1ak\n\u4fdd\u5b58\u6587\u4ef6\uff1aW<\/code><\/pre>\n\n\n\n<p>top\u547d\u4ee4\u680f\u4f4d\u4fe1\u606f\u7b80\u4ecb\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>us\uff1a\u7528\u6237\u7a7a\u95f4\nsy\uff1a\u5185\u6838\u7a7a\u95f4\nni\uff1a\u8c03\u6574nice\u65f6\u95f4\nid\uff1a\u7a7a\u95f2\nwa\uff1a\u7b49\u5f85IO\u65f6\u95f4\nhi\uff1a\u786c\u4e2d\u65ad\nsi\uff1a\u8f6f\u4e2d\u65ad\uff08\u6a21\u5f0f\u5207\u6362\uff09\nst\uff1a\u865a\u62df\u673a\u5077\u8d70\u7684\u65f6\u95f4<\/code><\/pre>\n\n\n\n<p>\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-d #\u6307\u5b9a\u5237\u65b0\u65f6\u95f4\u95f4\u9694\uff0c\u9ed8\u8ba4\u4e3a3\u79d2\n-b #\u5168\u90e8\u663e\u793a\u6240\u6709\u8fdb\u7a0b\n-n #\u5237\u65b0\u591a\u5c11\u6b21\u540e\u9000\u51fa\n-H #\u7ebf\u7a0b\u6a21\u5f0f<\/code><\/pre>\n\n\n\n<p><strong>htop<\/strong><\/p>\n\n\n\n<p>htop \u547d\u4ee4\u662f\u589e\u5f3a\u7248\u7684TOP\u547d\u4ee4\uff0c\u6765\u81eaEPEL\u6e90\uff0c\u6bd4top\u529f\u80fd\u66f4\u5f3a<\/p>\n\n\n\n<p>\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-d          #\u6307\u5b9a\u5ef6\u8fdf\u65f6\u95f4\n-u UserName #\u4ec5\u663e\u793a\u6307\u5b9a\u7528\u6237\u7684\u8fdb\u7a0b\n-s COLUME   #\u4ee5\u6307\u5b9a\u5b57\u6bb5\u8fdb\u884c\u6392\u5e8f<\/code><\/pre>\n\n\n\n<p>\u5b50\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>s\uff1a\u8ddf\u8e2a\u9009\u5b9a\u8fdb\u7a0b\u7684\u7cfb\u7edf\u8c03\u7528\nl\uff1a\u663e\u793a\u9009\u5b9a\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6\u5217\u8868\na\uff1a\u5c06\u9009\u5b9a\u7684\u8fdb\u7a0b\u7ed1\u5b9a\u81f3\u67d0\u6307\u5b9aCPU\u6838\u5fc3\nt\uff1a\u663e\u793a\u8fdb\u7a0b\u6811<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5185\u5b58\u7a7a\u95f4 free<\/h2>\n\n\n\n<p>free \u53ef\u4ee5\u663e\u793a\u5185\u5b58\u7a7a\u95f4\u4f7f\u7528\u72b6\u6001<\/p>\n\n\n\n<p>\u683c\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>free &#91;OPTION]<\/code><\/pre>\n\n\n\n<p>\u5e38\u7528\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-b \u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\n-m \u4ee5MB\u4e3a\u5355\u4f4d\n-g \u4ee5GB\u4e3a\u5355\u4f4d\n-h \u6613\u8bfb\u683c\u5f0f\n-o \u4e0d\u663e\u793a-\/+buffers\/cache\u884c\n-t \u663e\u793aRAM + swap\u7684\u603b\u548c\n-s n \u5237\u65b0\u95f4\u9694\u4e3an\u79d2\n-c n \u5237\u65b0n\u6b21\u540e\u5373\u9000\u51fa<\/code><\/pre>\n\n\n\n<p>linux\u5982\u4f55\u91ca\u653e\u7f13\u5b58\uff08\u6d4b\u8bd5\u73af\u5883\u624d\u4f1a\u4f7f\u7528\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 3 &gt; \/proc\/sys\/vm\/drop_caches<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u865a\u62df\u5185\u5b58\u4fe1\u606f vmstat<\/h2>\n\n\n\n<p>\u683c\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vmstat &#91;options] &#91;delay &#91;count]]<\/code><\/pre>\n\n\n\n<p>\u663e\u793a\u9879\u8bf4\u660e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>procs:\n  r\uff1a\u53ef\u8fd0\u884c\uff08\u6b63\u8fd0\u884c\u6216\u7b49\u5f85\u8fd0\u884c\uff09\u8fdb\u7a0b\u7684\u4e2a\u6570\uff0c\u548c\u6838\u5fc3\u6570\u6709\u5173\n  b\uff1a\u5904\u4e8e\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u6001\u7684\u8fdb\u7a0b\u4e2a\u6570(\u88ab\u963b\u585e\u7684\u961f\u5217\u7684\u957f\u5ea6)\n\nmemory\uff1a\n  swpd: \u4ea4\u6362\u5185\u5b58\u7684\u4f7f\u7528\u603b\u91cf\n  free\uff1a\u7a7a\u95f2\u7269\u7406\u5185\u5b58\u603b\u91cf\n  buffer\uff1a\u7528\u4e8ebuffer\u7684\u5185\u5b58\u603b\u91cf\n  cache\uff1a\u7528\u4e8ecache\u7684\u5185\u5b58\u603b\u91cf\n\nswap:\n  si\uff1a\u4ece\u78c1\u76d8\u4ea4\u6362\u8fdb\u5185\u5b58\u7684\u6570\u636e\u901f\u7387(kb\/s)\n  so\uff1a\u4ece\u5185\u5b58\u4ea4\u6362\u81f3\u78c1\u76d8\u7684\u6570\u636e\u901f\u7387(kb\/s)\n\nio\uff1a\n  bi\uff1a\u4ece\u5757\u8bbe\u5907\u8bfb\u5165\u6570\u636e\u5230\u7cfb\u7edf\u7684\u901f\u7387(kb\/s)\n  bo: \u4fdd\u5b58\u6570\u636e\u81f3\u5757\u8bbe\u5907\u7684\u901f\u7387\n\nsystem\uff1a\n  in: interrupts \u4e2d\u65ad\u901f\u7387\uff0c\u5305\u62ec\u65f6\u949f\n  cs: context switch \u8fdb\u7a0b\u5207\u6362\u901f\u7387\n\ncpu\uff1a\n  us:Time spent running non-kernel code\n  sy: Time spent running kernel code\n  id: Time spent idle. Linux 2.5.41\u524d,\u5305\u62ecIO-wait time.\n  wa: Time spent waiting for IO. 2.5.41\u524d\uff0c\u5305\u62ecin idle.\n  st: Time stolen from a virtual machine. 2.6.11\u524d, unknown.<\/code><\/pre>\n\n\n\n<p>\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-s \u663e\u793a\u5185\u5b58\u7684\u7edf\u8ba1\u6570\u636e<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u76d1\u89c6\u78c1\u76d8I\/O iotop<\/h2>\n\n\n\n<p>\u6765\u81ea\u4e8eiotop\u5305<\/p>\n\n\n\n<p>iotop\u547d\u4ee4\u662f\u4e00\u4e2a\u7528\u6765\u76d1\u89c6\u78c1\u76d8I\/O\u4f7f\u7528\u72b6\u51b5\u7684top\u7c7b\u5de5\u5177iotop\u5177\u6709\u4e0etop\u76f8\u4f3c\u7684UI\uff0c\u5176\u4e2d\u5305\u62ecPID\u3001\u7528<br>\u6237\u3001I\/O\u3001\u8fdb\u7a0b\u7b49\u76f8\u5173\u4fe1\u606f\uff0c\u53ef\u67e5\u770b\u6bcf\u4e2a\u8fdb\u7a0b\u662f\u5982\u4f55\u4f7f\u7528IO\u3002<\/p>\n\n\n\n<p>iotop\u8f93\u51fa<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u7b2c\u4e00\u884c\uff1aRead\u548cWrite\u901f\u7387\u603b\u8ba1<\/li><li>\u7b2c\u4e8c\u884c\uff1a\u5b9e\u9645\u7684Read\u548cWrite\u901f\u7387<\/li><li>\u7b2c\u4e09\u884c\uff1a\u53c2\u6570\u5982\u4e0b\uff1a \u7ebf\u7a0bID\uff08\u6309p\u5207\u6362\u4e3a\u8fdb\u7a0bID\uff09<br>\u4f18\u5148\u7ea7<br>\u7528\u6237<br>\u78c1\u76d8\u8bfb\u901f\u7387<br>\u78c1\u76d8\u5199\u901f\u7387<br>swap\u4ea4\u6362\u767e\u5206\u6bd4<br>IO\u7b49\u5f85\u6240\u5360\u7684\u767e\u5206\u6bd4<\/li><\/ul>\n\n\n\n<p>\u5e38\u7528\u53c2\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-o, --only\u53ea\u663e\u793a\u6b63\u5728\u4ea7\u751fI\/O\u7684\u8fdb\u7a0b\u6216\u7ebf\u7a0b\uff0c\u9664\u4e86\u4f20\u53c2\uff0c\u53ef\u4ee5\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u6309o\u751f\u6548\n-b, --batch\u975e\u4ea4\u4e92\u6a21\u5f0f\uff0c\u4e00\u822c\u7528\u6765\u8bb0\u5f55\u65e5\u5fd7\n-n NUM, --iter=NUM\u8bbe\u7f6e\u76d1\u6d4b\u7684\u6b21\u6570\uff0c\u9ed8\u8ba4\u65e0\u9650\u3002\u5728\u975e\u4ea4\u4e92\u6a21\u5f0f\u4e0b\u5f88\u6709\u7528\n-d SEC, --delay=SEC\u8bbe\u7f6e\u6bcf\u6b21\u76d1\u6d4b\u7684\u95f4\u9694\uff0c\u9ed8\u8ba41\u79d2\uff0c\u63a5\u53d7\u975e\u6574\u5f62\u6570\u636e\u4f8b\u59821.1\n-p PID, --pid=PID\u6307\u5b9a\u76d1\u6d4b\u7684\u8fdb\u7a0b\/\u7ebf\u7a0b\n-u USER, --user=USER\u6307\u5b9a\u76d1\u6d4b\u67d0\u4e2a\u7528\u6237\u4ea7\u751f\u7684I\/O\n-P, --processes\u4ec5\u663e\u793a\u8fdb\u7a0b\uff0c\u9ed8\u8ba4iotop\u663e\u793a\u6240\u6709\u7ebf\u7a0b\n-a, --accumulated\u663e\u793a\u7d2f\u79ef\u7684I\/O\uff0c\u800c\u4e0d\u662f\u5e26\u5bbd\n-k, --kilobytes\u4f7f\u7528kB\u5355\u4f4d\uff0c\u800c\u4e0d\u662f\u5bf9\u4eba\u53cb\u597d\u7684\u5355\u4f4d\u3002\u5728\u975e\u4ea4\u4e92\u6a21\u5f0f\u4e0b\uff0c\u811a\u672c\u7f16\u7a0b\u6709\u7528\n-t, --time \u52a0\u4e0a\u65f6\u95f4\u6233\uff0c\u975e\u4ea4\u4e92\u975e\u6a21\u5f0f\n-q, --quiet \u7981\u6b62\u5934\u51e0\u884c\uff0c\u975e\u4ea4\u4e92\u6a21\u5f0f\uff0c\u6709\u4e09\u79cd\u6307\u5b9a\u65b9\u5f0f\n-q \u53ea\u5728\u7b2c\u4e00\u6b21\u76d1\u6d4b\u65f6\u663e\u793a\u5217\u540d\n-qq \u6c38\u8fdc\u4e0d\u663e\u793a\u5217\u540d\n-qqq \u6c38\u8fdc\u4e0d\u663e\u793aI\/O\u6c47\u603b<\/code><\/pre>\n\n\n\n<p>\u4ea4\u4e92\u6309\u952e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>left\u548cright\u65b9\u5411\u952e\uff1a\u6539\u53d8\u6392\u5e8f\nr\uff1a\u53cd\u5411\u6392\u5e8f\no\uff1a\u5207\u6362\u81f3\u9009\u9879--only\np\uff1a\u5207\u6362\u81f3--processes\u9009\u9879\na\uff1a\u5207\u6362\u81f3--accumulated\u9009\u9879\nq\uff1a\u9000\u51fa\ni\uff1a\u6539\u53d8\u7ebf\u7a0b\u7684\u4f18\u5148\u7ea7<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u663e\u793a\u7f51\u7edc\u5e26\u5bbd\u4f7f\u7528\u60c5\u51b5 iftop<\/h2>\n\n\n\n<p>\u901a\u8fc7EPEL\u6e90\u7684 iftop \u5305<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>iftop -ni eth0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u67e5\u770b\u7f51\u7edc\u5b9e\u65f6\u541e\u5410\u91cf nload<\/h2>\n\n\n\n<p>nload \u662f\u4e00\u4e2a\u5b9e\u65f6\u76d1\u63a7\u7f51\u7edc\u6d41\u91cf\u548c\u5e26\u5bbd\u4f7f\u7528\u60c5\u51b5\uff0c\u4ee5\u6570\u503c\u548c\u52a8\u6001\u56fe\u5c55\u793a\u8fdb\u51fa\u7684\u6d41\u91cf\u60c5\u51b5,\u901a\u8fc7EPEL\u6e90\u5b89\u88c5\u3002<\/p>\n\n\n\n<p>\u754c\u9762\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4e0a\u4e0b\u65b9\u5411\u952e\u3001\u5de6\u53f3\u65b9\u5411\u952e\u3001enter\u952e\u6216\u8005tab\u952e\u90fd\u5c31\u53ef\u4ee5\u5207\u6362\u67e5\u770b\u591a\u4e2a\u7f51\u5361\u7684\u6d41\u91cf\u60c5\u51b5\n\u6309 F2 \u663e\u793a\u9009\u9879\u7a97\u53e3\n\u6309 q \u6216\u8005 Ctrl+C \u9000\u51fa nload<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u9ed8\u8ba4\u53ea\u67e5\u770b\u7b2c\u4e00\u4e2a\u7f51\u7edc\u7684\u6d41\u91cf\u8fdb\u51fa\u60c5\u51b5\nnload\n#\u5728nload\u540e\u9762\u6307\u5b9a\u7f51\u5361\uff0c\u53ef\u4ee5\u6307\u5b9a\u591a\u4e2a,\u6309\u5de6\u53f3\u952e\u5206\u522b\u663e\u793a\u7f51\u5361\u72b6\u6001\nnload eth0 eth1\n#\u8bbe\u7f6e\u5237\u65b0\u95f4\u9694\uff1a\u9ed8\u8ba4\u5237\u65b0\u95f4\u9694\u662f100\u6beb\u79d2\uff0c\u53ef\u901a\u8fc7 -t \u547d\u4ee4\u8bbe\u7f6e\u5237\u65b0\u65f6\u95f4\uff08\u5355\u4f4d\u662f\u6beb\u79d2\uff09\nnload -t 500 eth0\n#\u8bbe\u7f6e\u5355\u4f4d\uff1a\u663e\u793a\u4e24\u79cd\u5355\u4f4d\u4e00\u79cd\u662f\u663e\u793aBit\/s\u3001\u4e00\u79cd\u662f\u663e\u793aByte\/s\uff0c\u9ed8\u8ba4\u662f\u4ee5Bit\/s\uff0c\u4e5f\u53ef\u4e0d\u663e\u793a\/s\n#-u h|b|k|m|g|H|B|K|M|G \u8868\u793a\u7684\u542b\u4e49\uff1a h: auto, b: Bit\/s, k: kBit\/s, m: MBit\/s, H:\nauto, B: Byte\/s, K: kByte\/s, M: MByte\/s\nnload -u M eth0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u7f51\u7edc\u76d1\u89c6\u5de5\u5177iptraf-ng<\/h2>\n\n\n\n<p>\u6765\u81ea\u4e8eiptraf-ng\u5305,\u53ef\u4ee5\u8fdb\u7f51\u7edc\u8fdb\u884c\u76d1\u63a7,\u5bf9\u7ec8\u7aef\u7a97\u53e3\u5927\u5c0f\u6709\u8981\u6c42<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7cfb\u7edf\u8d44\u6e90\u7edf\u8ba1 dstat<\/h2>\n\n\n\n<p>dstat\u7531pcp-system-tools\u5305\u63d0\u4f9b\uff0c\u4f46\u5b89\u88c5dstat\u5305\u5373\u53ef, \u53ef\u7528\u4e8e\u4ee3\u66ff vmstat,iostat\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u683c\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dstat &#91;-afv] &#91;options..] &#91;delay &#91;count]]<\/code><\/pre>\n\n\n\n<p>\u5e38\u7528\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-c \u663e\u793acpu\u76f8\u5173\u4fe1\u606f\n-C #,#,...,total\n-d \u663e\u793adisk\u76f8\u5173\u4fe1\u606f\n-D total,sda,sdb,...\n-g \u663e\u793apage\u76f8\u5173\u7edf\u8ba1\u6570\u636e\n-m \u663e\u793amemory\u76f8\u5173\u7edf\u8ba1\u6570\u636e\n-n \u663e\u793anetwork\u76f8\u5173\u7edf\u8ba1\u6570\u636e\n-p \u663e\u793aprocess\u76f8\u5173\u7edf\u8ba1\u6570\u636e\n-r \u663e\u793aio\u8bf7\u6c42\u76f8\u5173\u7684\u7edf\u8ba1\u6570\u636e\n-s \u663e\u793aswapped\u76f8\u5173\u7684\u7edf\u8ba1\u6570\u636e\n--tcp\n--udp\n--unix\n--raw\n--socket\n--ipc\n--top-cpu\uff1a\u663e\u793a\u6700\u5360\u7528CPU\u7684\u8fdb\u7a0b\n--top-io: \u663e\u793a\u6700\u5360\u7528io\u7684\u8fdb\u7a0b\n--top-mem: \u663e\u793a\u6700\u5360\u7528\u5185\u5b58\u7684\u8fdb\u7a0b\n--top-latency: \u663e\u793a\u5ef6\u8fdf\u6700\u5927\u7684\u8fdb\u7a0b<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u67e5\u770b\u8fdb\u7a0b\u6253\u5f00\u6587\u4ef6 lsof<\/h2>\n\n\n\n<p>lsof\uff1alist open files\uff0c\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u6587\u4ef6\u7684\u5de5\u5177\u3002\u5728linux\u73af\u5883\u4e0b\uff0c\u4e00\u5207\u7686\u6587\u4ef6\uff0c\u7528\u6237\u901a\u8fc7\u6587\u4ef6\u4e0d\u4ec5\u53ef\u4ee5<br>\u8bbf\u95ee\u5e38\u89c4\u6570\u636e\uff0c\u8fd8\u53ef\u4ee5\u8bbf\u95ee\u7f51\u7edc\u8fde\u63a5\u548c\u786c\u4ef6\u5982\u4f20\u8f93\u63a7\u5236\u534f\u8bae (TCP) \u548c\u7528\u6237\u6570\u636e\u62a5\u534f\u8bae (UDP)\u5957\u63a5\u5b57\u7b49\uff0c<br>\u7cfb\u7edf\u5728\u540e\u53f0\u90fd\u4e3a\u8be5\u5e94\u7528\u7a0b\u5e8f\u5206\u914d\u4e86\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002<\/p>\n\n\n\n<p>\u547d\u4ee4\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-a\uff1a\u5217\u51fa\u6253\u5f00\u6587\u4ef6\u5b58\u5728\u7684\u8fdb\u7a0b\n-c&lt;\u8fdb\u7a0b\u540d&gt;\uff1a\u5217\u51fa\u6307\u5b9a\u8fdb\u7a0b\u6240\u6253\u5f00\u7684\u6587\u4ef6\n-g\uff1a\u5217\u51faGID\u53f7\u8fdb\u7a0b\u8be6\u60c5\n-d&lt;\u6587\u4ef6\u53f7&gt;\uff1a\u5217\u51fa\u5360\u7528\u8be5\u6587\u4ef6\u53f7\u7684\u8fdb\u7a0b\n+d&lt;\u76ee\u5f55&gt;\uff1a\u5217\u51fa\u76ee\u5f55\u4e0b\u88ab\u6253\u5f00\u7684\u6587\u4ef6\n+D&lt;\u76ee\u5f55&gt;\uff1a\u9012\u5f52\u5217\u51fa\u76ee\u5f55\u4e0b\u88ab\u6253\u5f00\u7684\u6587\u4ef6\n-n&lt;\u76ee\u5f55&gt;\uff1a\u5217\u51fa\u4f7f\u7528NFS\u7684\u6587\u4ef6\n-i&lt;\u6761\u4ef6&gt;\uff1a\u5217\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u8fdb\u7a0b(4\u30016\u3001\u534f\u8bae\u3001:\u7aef\u53e3\u3001 @ip )\n-p&lt;\u8fdb\u7a0b\u53f7&gt;\uff1a\u5217\u51fa\u6307\u5b9a\u8fdb\u7a0b\u53f7\u6240\u6253\u5f00\u7684\u6587\u4ef6\n-u\uff1a\u5217\u51faUID\u53f7\u8fdb\u7a0b\u8be6\u60c5\n-h\uff1a\u663e\u793a\u5e2e\u52a9\u4fe1\u606f\n-v\uff1a\u663e\u793a\u7248\u672c\u4fe1\u606f\u3002\n-n: \u4e0d\u53cd\u5411\u89e3\u6790\u7f51\u7edc\u540d\u5b57<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u5217\u51fa\u5f53\u524d\u6240\u6709\u6253\u5f00\u7684\u6587\u4ef6\nlsof\n#\u67e5\u770b\u5f53\u524d\u54ea\u4e2a\u8fdb\u7a0b\u6b63\u5728\u4f7f\u7528\u6b64\u6587\u4ef6\nlsof \/var\/log\/nginx\/access.log\n#\u67e5\u770b\u7531\u767b\u9646\u7528\u6237\u542f\u52a8\u800c\u975e\u7cfb\u7edf\u542f\u52a8\u7684\u8fdb\u7a0b\nlsof `tty`\n#\u6307\u5b9a\u8fdb\u7a0b\u53f7\uff0c\u53ef\u4ee5\u67e5\u770b\u8be5\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6\nlsof 1\n#\u67e5\u770b\u6307\u5b9a\u7a0b\u5e8f\u6253\u5f00\u7684\u6587\u4ef6\nlsof -c nginx\n#\u67e5\u770b\u6307\u5b9a\u7528\u6237\u6253\u5f00\u7684\u6587\u4ef6\nlsof -u root | more\n#\u67e5\u770b\u6307\u5b9a\u76ee\u5f55\u4e0b\u88ab\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u53c2\u6570+D\u4e3a\u9012\u5f52\u5217\u51fa\u76ee\u5f55\u4e0b\u88ab\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u53c2\u6570+d\u4e3a\u5217\u51fa\u76ee\u5f55\u4e0b\u88ab\u6253\u5f00\u7684\u6587\u4ef6\nlsof +D \/var\/log\/\nlsof +d \/var\/log\/\n#\u67e5\u770b\u6240\u6709\u7f51\u7edc\u8fde\u63a5\uff0c\u901a\u8fc7\u53c2\u6570-i\u67e5\u770b\u7f51\u7edc\u8fde\u63a5\u7684\u60c5\u51b5\uff0c\u5305\u62ec\u8fde\u63a5\u7684ip\u3001\u7aef\u53e3\u7b49\u4ee5\u53ca\u4e00\u4e9b\u670d\u52a1\u7684\u8fde\u63a5\u60c5\u51b5\uff0c\u4f8b\n\u5982\uff1asshd\u7b49\u3002\u4e5f\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9aip\u67e5\u770b\u8be5ip\u7684\u7f51\u7edc\u8fde\u63a5\u60c5\u51b5\nlsof -i \u2013n\nlsof -i@127.0.0.1\n#\u67e5\u770b\u7aef\u53e3\u8fde\u63a5\u60c5\u51b5\uff0c\u901a\u8fc7\u53c2\u6570-i:\u7aef\u53e3\u53ef\u4ee5\u67e5\u770b\u7aef\u53e3\u7684\u5360\u7528\u60c5\u51b5\uff0c-i\u53c2\u6570\u8fd8\u6709\u67e5\u770b\u534f\u8bae\uff0cip\u7684\u8fde\u63a5\u60c5\u51b5\u7b49\nlsof -i :80 -n\n#\u67e5\u770b\u6307\u5b9a\u72b6\u6001\u7684\u7f51\u7edc\u8fde\u63a5\uff0c-n:no host names, -P:no port names,-i TCP\u6307\u5b9a\u534f\u8bae\uff0c-s\u6307\u5b9a\u534f\u8bae\n\u72b6\u6001\u901a\u8fc7\u591a\u4e2a\u53c2\u6570\u53ef\u4ee5\u6e05\u6670\u7684\u67e5\u770b\u7f51\u7edc\u8fde\u63a5\u60c5\u51b5\u3001\u534f\u8bae\u8fde\u63a5\u60c5\u51b5\u7b49\nlsof -n -P -i TCP -s TCP:ESTABLISHED<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4fe1\u53f7\u53d1\u9001 kill<\/h2>\n\n\n\n<p>kill\uff1a\u5185\u90e8\u547d\u4ee4\uff0c\u53ef\u7528\u6765\u5411\u8fdb\u7a0b\u53d1\u9001\u63a7\u5236\u4fe1\u53f7\uff0c\u4ee5\u5b9e\u73b0\u5bf9\u8fdb\u7a0b\u7ba1\u7406\uff0c\u6bcf\u4e2a\u4fe1\u53f7\u5bf9\u5e94\u4e00\u4e2a\u6570\u5b57\uff0c\u4fe1\u53f7\u540d\u79f0\u4ee5SIG\u5f00\u5934\uff08\u53ef\u7701\u7565\uff09\uff0c\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002<\/p>\n\n\n\n<p>\u663e\u793a\u5f53\u524d\u7cfb\u7edf\u53ef\u7528\u4fe1\u53f7\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kill -l\ntrap -l<\/code><\/pre>\n\n\n\n<p>\u67e5\u770b\u5e2e\u52a9\uff1aman 7 signal<\/p>\n\n\n\n<p>\u5e38\u7528\u4fe1\u53f7\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1) SIGHUP \u65e0\u987b\u5173\u95ed\u8fdb\u7a0b\u800c\u8ba9\u5176\u91cd\u8bfb\u914d\u7f6e\u6587\u4ef6\n2) SIGINT \u4e2d\u6b62\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\uff1b\u76f8\u5f53\u4e8eCtrl+c\n3) SIGQUIT \u76f8\u5f53\u4e8ectrl+\\\n9) SIGKILL \u5f3a\u5236\u6740\u6b7b\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b,\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u4e22\u5931,\u614e\u7528!\n15) SIGTERM \u7ec8\u6b62\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u9ed8\u8ba4\u4fe1\u53f7\n18) SIGCONT \u7ee7\u7eed\u8fd0\u884c\n19) SIGSTOP \u540e\u53f0\u4f11\u7720<\/code><\/pre>\n\n\n\n<p>\u6307\u5b9a\u4fe1\u53f7\u7684\u65b9\u6cd5 :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4fe1\u53f7\u7684\u6570\u5b57\u6807\u8bc6\uff1a1, 2, 9<\/li><li>\u4fe1\u53f7\u5b8c\u6574\u540d\u79f0\uff1aSIGHUP\uff0csighup<\/li><li>\u4fe1\u53f7\u7684\u7b80\u5199\u540d\u79f0\uff1aHUP\uff0chup<\/li><\/ul>\n\n\n\n<p>\u6309PID\u5411\u8fdb\u7a0b\u53d1\u9001\u4fe1\u53f7\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kill &#91;-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l &#91;sigspec]<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kill -1 PID\nkill -n 1 PID\nkill -s TERM PID<\/code><\/pre>\n\n\n\n<p>\u6309\u540d\u79f0\u5411\u8fdb\u7a0b\u53d1\u9001\u4fe1\u53f7\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>killall &#91;-SIGNAL] comm<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>killall ping<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a\u5229\u7528 0 \u4fe1\u53f7\u5b9e\u73b0\u8fdb\u7a0b\u7684\u5065\u5eb7\u6027\u68c0\u67e5<\/p>\n\n\n\n<p>\u8fd4\u56de0\u8868\u793a\u8fdb\u7a0b\u5065\u5eb7\uff0c\u6b64\u65b9\u5f0f\u6709\u5c40\u9650\u6027\uff0c\u5373\u4f7f\u8fdb\u7a0b\u5904\u4e8e\u505c\u6b62\u6216\u50f5\u5c38\u72b6\u6001\uff0c\u6b64\u65b9\u5f0f\u4ecd\u7136\u8ba4\u4e3a\u8fdb\u7a0b\u662f\u5065\u5eb7\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@DMIT-iJboSKPbP4:~# killall -0 php-fpm7.4\nroot@DMIT-iJboSKPbP4:~# echo $?\n0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f5c\u4e1a\u7ba1\u7406<\/h2>\n\n\n\n<p>Linux\u7684\u4f5c\u4e1a\u63a7\u5236<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u524d\u53f0\u4f5c\u4e1a\uff1a\u901a\u8fc7\u7ec8\u7aef\u542f\u52a8\uff0c\u4e14\u542f\u52a8\u540e\u4e00\u76f4\u5360\u636e\u7ec8\u7aef<\/li><li>\u540e\u53f0\u4f5c\u4e1a\uff1a\u53ef\u901a\u8fc7\u7ec8\u7aef\u542f\u52a8\uff0c\u4f46\u542f\u52a8\u540e\u5373\u8f6c\u5165\u540e\u53f0\u8fd0\u884c\uff08\u91ca\u653e\u7ec8\u7aef\uff09<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"496\" src=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a2-1024x496.jpg\" alt=\"\" class=\"wp-image-264\" srcset=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a2-1024x496.jpg 1024w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a2-300x145.jpg 300w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a2-768x372.jpg 768w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/06\/20220602a2.jpg 1277w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8ba9\u4f5c\u4e1a\u8fd0\u884c\u4e8e\u540e\u53f0<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8fd0\u884c\u4e2d\u7684\u4f5c\u4e1a\uff1a Ctrl+z<\/li><li>\u5c1a\u672a\u542f\u52a8\u7684\u4f5c\u4e1a\uff1a COMMAND &amp;<\/li><\/ul>\n\n\n\n<p>\u540e\u53f0\u4f5c\u4e1a\u867d\u7136\u88ab\u9001\u5f80\u540e\u53f0\u8fd0\u884c\uff0c\u4f46\u5176\u4f9d\u7136\u4e0e\u7ec8\u7aef\u76f8\u5173\uff1b\u9000\u51fa\u7ec8\u7aef\uff0c\u5c06\u5173\u95ed\u540e\u53f0\u4f5c\u4e1a\u3002\u5982\u679c\u5e0c\u671b\u9001\u5f80\u540e\u53f0<br>\u540e\uff0c\u5265\u79bb\u4e0e\u7ec8\u7aef\u7684\u5173\u7cfb\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>nohup COMMAND &amp;&gt;\/dev\/null &amp;<\/li><li>screen\uff1bCOMMAND<\/li><li>tmux\uff1bCOMMAND<\/li><\/ul>\n\n\n\n<p>\u67e5\u770b\u5f53\u524d\u7ec8\u7aef\u6240\u6709\u4f5c\u4e1a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>jobs<\/code><\/pre>\n\n\n\n<p>\u4f5c\u4e1a\u63a7\u5236\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fg &#91;&#91;%]JOB_NUM]\uff1a\u628a\u6307\u5b9a\u7684\u540e\u53f0\u4f5c\u4e1a\u8c03\u56de\u524d\u53f0\nbg &#91;&#91;%]JOB_NUM]\uff1a\u8ba9\u9001\u5f80\u540e\u53f0\u7684\u4f5c\u4e1a\u5728\u540e\u53f0\u7ee7\u7eed\u8fd0\u884c\nkill &#91;%JOB_NUM]\uff1a \u7ec8\u6b62\u6307\u5b9a\u7684\u4f5c\u4e1a<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e76\u884c\u8fd0\u884c<\/h2>\n\n\n\n<p>\u5229\u7528\u540e\u53f0\u6267\u884c\uff0c\u5b9e\u73b0\u5e76\u884c\u529f\u80fd\uff0c\u5373\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u8fdb\u7a0b\uff0c\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n\n\n\n<p>\u540c\u65f6ping\u591a\u4e2a\u5730\u5740\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(ping -c3 127.1 &amp;);(ping -c3 127.2 &amp;);(ping -c3 127.3 &amp;)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u603b\u7ed3\u4e86\u5927\u90e8\u5206\u5e38\u7528\u7684linux\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177 \u8fdb\u7a0b\u6811 pstree pstree \u53ef\u4ee5\u7528\u6765\u663e\u793a\u8fdb\u7a0b\u7684\u7236\u5b50\u5173\u7cfb\uff0c\u4ee5\u6811\u5f62\u7ed3\u6784\u663e\u793a\u3002 \u683c\u5f0f\uff1a \u5e38\u7528\u9009\u9879\uff1a \u8fdb\u7a0b\u4fe1\u606f ps ps \u5373 process state\uff0c\u53ef\u4ee5\u8fdb\u7a0b\u5f53\u524d\u72b6\u6001\u7684\u5feb\u7167\uff0c\u9ed8\u8ba4\u663e\u793a\u5f53\u524d\u7ec8&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[41],"topic":[],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-linux","tag-41"],"_links":{"self":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=262"}],"version-history":[{"count":1,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":265,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/262\/revisions\/265"}],"wp:attachment":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=262"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}