{"id":782,"date":"2020-12-21T22:15:30","date_gmt":"2020-12-21T14:15:30","guid":{"rendered":"https:\/\/byy3.com\/782.html"},"modified":"2021-02-08T19:00:54","modified_gmt":"2021-02-08T11:00:54","slug":"linux%e5%86%85%e5%ad%98%e6%b8%85%e7%90%86","status":"publish","type":"post","link":"https:\/\/byy3.com\/?p=782","title":{"rendered":"Linux\u5185\u5b58\u6e05\u7406"},"content":{"rendered":"<p>\u521b\u5efa\u811a\u672ccleancache.sh<\/p>\n<pre>#!\/bin\/bash\nsync\necho 1 &gt; \/proc\/sys\/vm\/drop_caches\necho 2 &gt; \/proc\/sys\/vm\/drop_caches\necho 3 &gt; \/proc\/sys\/vm\/drop_caches\n\n\u521b\u5efa\u597d\u4e86\u811a\u672c\u4e4b\u540e\u9700\u8981chmod +x cleanchache.sh \n\n<\/pre>\n<p>\u67e5\u8be2\u670d\u52a1\u5668\u5185\u5b58\u5360\u7528\u60c5\u51b5\uff0c\u4f7f\u7528\u547d\u4ee4\uff1a<\/p>\n<pre class=\"prettyprint\"><code class=\"has-numbering\">du -sh \/* | sort -nr\n<\/code><\/pre>\n<p>\u901a\u8fc7\u4e0a\u8fb9\u7684\u547d\u4ee4\u67e5\u8be2\u4f1a\u663e\u793a\u51fa\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u518d\u8fdb\u5165\u5927\u5c0f\u5f02\u5e38\u7684\u6587\u4ef6\uff08\u6bd4\u5982\uff1a\u5728usr\u6587\u4ef6\u5927\u5c0f\u5f02\u5e38\uff0c\u8fdb\u5165usr,\u8fd0\u884c\u547d\u4ee4 : du -sh \/usr\/*|sort -nr \uff09\uff0c\u8fd9\u6837\u5c31\u80fd\u5b9a\u4f4d\u5230\u5f02\u5e38\u5927\u5c0f\u7684\u6587\u4ef6\u5e76\u5220\u9664\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u4f1a\u662f\u4ea7\u751f\u7684\u65e5\u5fd7\u6ca1\u6709\u53ca\u65f6\u6e05\u7406\u5bfc\u81f4\u7684\u670d\u52a1\u5668\u5185\u5b58\u4e0d\u8db3\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5728Linux\u670d\u52a1\u5668\u4e0a\u4f7f\u7528Jmeter\u8fdb\u884c\u538b\u6d4b\u7684\u65f6\u5019\uff0c\u9047\u5230\u4e86\u4e00\u4e2a\u9519\u8bef\uff1a<\/p>\n<p><img decoding=\"async\" data-original=\"https:\/\/img2018.cnblogs.com\/blog\/351541\/201911\/351541-20191122141601426-1920486178.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" title=\"Linux\u5185\u5b58\u6e05\u7406\u63d2\u56fe\" alt=\"Linux\u5185\u5b58\u6e05\u7406\u63d2\u56fe\" \/>\u6839\u636e\u8fd9\u91cc\u7684\u63d0\u793a\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c0000000, 1073741824, 0) failed; error='Cannot allocate memory' (errno=12)\n#\n# There is insufficient memory for the Java Runtime Environment to continue.\n# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.\n# An error report file with more information is saved as:\n# \/home\/HAO\/IM\/hs_err_pid20194.log<\/pre>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<p>\u53bb\u67e5\u4e86\u4e00\u4e0b\u5185\u5b58\u60c5\u51b5\uff0c\u53ef\u4ee5\u770b\u5230\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>[root@qatest1 IM]# free -m\n total used free shared buffers cached\nMem: 8001 7881 120 0 4 416\n-\/+ buffers\/cache: 7460 541\nSwap: 0 0 0<\/pre>\n<\/div>\n<p>\u786e\u5b9e\u662f\u5185\u5b58\u4e0d\u8db3\u4e86\uff0c\u53bb\u67e5\u4e00\u4e0b\uff0c\u91cc\u9762\u6709\u5f88\u591a\u4e0d\u8ba4\u8bc6\u7684\u670d\u52a1\u3002\u4e8e\u662f\u51c6\u5907\u6e05\u7406\u4e00\u4e0b\u3002<\/p>\n<p>\u5199\u4e86\u4e2a\u811a\u672c\u8fd0\u884c\uff0c\u4ee5\u540e\u53ef\u4ee5\u590d\u7528\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>kill -9 <code>ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head | awk &#039;{print $2}&#039;<\/code><\/pre>\n<\/div>\n<p>\u5982\u679c\u6267\u884c\u4e4b\u540e\u5728\u67e5\u8be2\uff0c\u53d1\u73b0\u5185\u5b58\u8fd8\u662f\u4e0d\u591f\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u591a\u6267\u884c\u51e0\u6b21\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>kill -9 <code>ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head -K 50| awk &#039;{print $2}&#039;<\/code><\/pre>\n<\/div>\n<p>\u518d\u6b21\u67e5\u8be2\uff0c\u53ef\u89c1\u5df2\u7ecf\u6709\u4e0d\u5c11\u53ef\u7528\u5185\u5b58\u4e86\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>[root@qatest1 IM]# free -m\n total used free shared buffers cached\nMem: 8001 2460 5541 0 5 663\n-\/+ buffers\/cache: 1791 6209\nSwap: 0 0 0<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>\u4e0b\u9762\u8865\u5145\u4e00\u4e0b\u66f4\u591a\u7684\u547d\u4ee4\uff1b<\/p>\n<p>linux\u4e0b\u83b7\u53d6\u5360\u7528CPU\u8d44\u6e90\u6700\u591a\u768410\u4e2a\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u7ec4\u5408\uff1a<\/p>\n<p>ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head<\/p>\n<p>linux\u4e0b\u83b7\u53d6\u5360\u7528\u5185\u5b58\u8d44\u6e90\u6700\u591a\u768410\u4e2a\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u7ec4\u5408\uff1a<\/p>\n<p>ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head<\/p>\n<p>\u547d\u4ee4\u7ec4\u5408\u89e3\u6790\uff08\u9488\u5bf9CPU\u7684\uff0cMEN\u4e5f\u540c\u6837\u9053\u7406\uff09\uff1a<\/p>\n<p>ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head<\/p>\n<p>\u8be5\u547d\u4ee4\u7ec4\u5408\u5b9e\u9645\u4e0a\u662f\u4e0b\u9762\u4e24\u53e5\u547d\u4ee4\uff1a<\/p>\n<p>ps aux|head -1<\/p>\n<p>ps aux|grep -v PID|sort -rn -k +3|head<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e0b\u547d\u4ee4\u67e5\u4f7f\u7528\u5185\u5b58\u6700\u591a\u768410\u4e2a\u8fdb\u7a0b<\/p>\n<p><strong>\u67e5\u770b\u5360\u7528cpu\u6700\u9ad8\u7684\u8fdb\u7a0b<\/strong><\/p>\n<p><a href=\"https:\/\/byy3.com\/go\/?url=http:\/\/www.111cn.net\/fw\/photo.html\" target=\"_blank\" rel=\"noopener\" rel=\"nofollow\" >ps<\/a>\u00a0aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head<\/p>\n<p>\u6216\u8005top \uff08\u7136\u540e\u6309\u4e0bM\uff0c\u6ce8\u610f\u8fd9\u91cc\u662f\u5927\u5199\uff09<\/p>\n<p><strong>\u67e5\u770b\u5360\u7528\u5185\u5b58\u6700\u9ad8\u7684\u8fdb\u7a0b<strong>**<\/strong>\u00a0<\/strong><\/p>\n<p>ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head<\/p>\n<p><strong>\u4e00\u952e\u6e05\u7406\u811a\u672ckill_Xvfb.sh# ps -ef | <span class=\"hljs-keyword\">grep<\/span> Xvfb | <span class=\"hljs-keyword\">grep<\/span> -v <span class=\"hljs-keyword\">grep<\/span> | awk <span class=\"hljs-string\">'{print $2}'<\/span> | xargs <span class=\"hljs-keyword\">kill<\/span> -<span class=\"hljs-number\">9<\/span><\/strong><\/p>\n<p>\u6216\u8005 ps -aux | grep Xvfb<\/p>\n<p>\u6216\u8005top \uff08\u7136\u540e\u6309\u4e0bP\uff0c\u6ce8\u610f\u8fd9\u91cc\u662f\u5927\u5199\uff09<\/p>\n<p><strong>\u8be5\u547d\u4ee4\u7ec4\u5408\u5b9e\u9645\u4e0a\u662f\u4e0b\u9762\u4e24\u53e5\u547d\u4ee4\uff1a<\/strong><\/p>\n<p>ps aux|head -1<br \/>\nps aux|grep -v PID|sort -rn -k +3|head<\/p>\n<p>\u5176\u4e2d\u7b2c\u4e00\u53e5\u4e3b\u8981\u662f\u4e3a\u4e86\u83b7\u53d6\u6807\u9898\uff08USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND\uff09\u3002<br \/>\n\u63a5\u4e0b\u6765\u7684grep -v PID\u662f\u5c06ps aux\u547d\u4ee4\u5f97\u5230\u7684\u6807\u9898\u53bb\u6389\uff0c\u5373grep\u4e0d\u5305\u542bPID\u8fd9\u4e09\u4e2a\u5b57\u6bcd\u7ec4\u5408\u7684\u884c\uff0c\u518d\u5c06\u5176\u4e2d\u7ed3\u679c\u4f7f\u7528sort\u6392\u5e8f\u3002<br \/>\nsort -rn -k +3\u8be5\u547d\u4ee4\u4e2d\u7684-rn\u7684r\u8868\u793a\u662f\u7ed3\u679c\u5012\u5e8f\u6392\u5217\uff0cn\u4e3a\u4ee5\u6570\u503c\u5927\u5c0f\u6392\u5e8f\uff0c\u800c-k +3\u5219\u662f\u9488\u5bf9\u7b2c3\u5217\u7684\u5185\u5bb9\u8fdb\u884c\u6392\u5e8f\uff0c\u518d\u4f7f\u7528head\u547d\u4ee4\u83b7\u53d6\u9ed8\u8ba4\u524d10\u884c\u6570\u636e\u3002(\u5176\u4e2d\u7684|\u8868\u793a\u7ba1\u9053\u64cd\u4f5c)<\/p>\n<p><strong>\u8865\u5145:\u5185\u5bb9\u89e3\u91ca<\/strong><\/p>\n<p>PID\uff1a\u8fdb\u7a0b\u7684ID<br \/>\nUSER\uff1a\u8fdb\u7a0b\u6240\u6709\u8005<br \/>\nPR\uff1a\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u522b\uff0c\u8d8a\u5c0f\u8d8a\u4f18\u5148\u88ab\u6267\u884c<br \/>\nNInice\uff1a\u503c<br \/>\nVIRT\uff1a\u8fdb\u7a0b\u5360\u7528\u7684\u865a\u62df\u5185\u5b58<br \/>\nRES\uff1a\u8fdb\u7a0b\u5360\u7528\u7684\u7269\u7406\u5185\u5b58<br \/>\nSHR\uff1a\u8fdb\u7a0b\u4f7f\u7528\u7684\u5171\u4eab\u5185\u5b58<br \/>\nS\uff1a\u8fdb\u7a0b\u7684\u72b6\u6001\u3002S\u8868\u793a\u4f11\u7720\uff0cR\u8868\u793a\u6b63\u5728\u8fd0\u884c\uff0cZ\u8868\u793a\u50f5\u6b7b\u72b6\u6001\uff0cN\u8868\u793a\u8be5\u8fdb\u7a0b\u4f18\u5148\u503c\u4e3a\u8d1f\u6570<br \/>\n%CPU\uff1a\u8fdb\u7a0b\u5360\u7528CPU\u7684\u4f7f\u7528\u7387<br \/>\n%MEM\uff1a\u8fdb\u7a0b\u4f7f\u7528\u7684\u7269\u7406\u5185\u5b58\u548c\u603b\u5185\u5b58\u7684\u767e\u5206\u6bd4<br \/>\nTIME+\uff1a\u8be5\u8fdb\u7a0b\u542f\u52a8\u540e\u5360\u7528\u7684\u603b\u7684CPU\u65f6\u95f4\uff0c\u5373\u5360\u7528CPU\u4f7f\u7528\u65f6\u95f4\u7684\u7d2f\u52a0\u503c\u3002<br \/>\nCOMMAND\uff1a\u8fdb\u7a0b\u542f\u52a8\u547d\u4ee4\u540d\u79f0<\/p>\n<p>&nbsp;<\/p>\n<p>\u9700\u8981root\u7528\u6237\u8fd0\u884c<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u4f7f\u7528\u5185\u5b58\u6700\u591a\u7684K\u4e2a\u8fdb\u7a0b<\/p>\n<p>\u65b9\u6cd51\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>ps -aux | sort -k4nr | head -K<\/pre>\n<\/div>\n<p>\u5982\u679c\u662f10\u4e2a\u8fdb\u7a0b\uff0cK=10\uff0c\u5982\u679c\u662f\u6700\u9ad8\u7684\u4e09\u4e2a\uff0cK=3<\/p>\n<p><strong>\u8bf4\u660e\uff1a<\/strong>ps -aux\u4e2d\uff08a\u6307\u4ee3all\u2014\u2014\u6240\u6709\u7684\u8fdb\u7a0b\uff0cu\u6307\u4ee3userid\u2014\u2014\u6267\u884c\u8be5\u8fdb\u7a0b\u7684\u7528\u6237id\uff0cx\u6307\u4ee3\u663e\u793a\u6240\u6709\u7a0b\u5e8f\uff0c\u4e0d\u4ee5\u7ec8\u7aef\u673a\u6765\u533a\u5206\uff09<\/p>\n<p>ps -aux\u7684\u8f93\u51fa\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND\nroot 1 0.0 0.0 19352 1308 ? Ss Jul29 0:00 \/sbin\/init\nroot 2 0.0 0.0 0 0 ? S Jul29 0:00 [kthreadd]\nroot 3 0.0 0.0 0 0 ? S Jul29 0:11 [migration\/0]<\/pre>\n<\/div>\n<p>sort -k4nr\u4e2d\uff08k\u4ee3\u8868\u4ece\u7b2c\u51e0\u4e2a\u4f4d\u7f6e\u5f00\u59cb\uff0c\u540e\u9762\u7684\u6570\u5b574\u5373\u662f\u5176\u5f00\u59cb\u4f4d\u7f6e\uff0c\u7ed3\u675f\u4f4d\u7f6e\u5982\u679c\u6ca1\u6709\uff0c\u5219\u9ed8\u8ba4\u5230\u6700\u540e\uff1bn\u6307\u4ee3numberic sort\uff0c\u6839\u636e\u5176\u6570\u503c\u6392\u5e8f\uff1br\u6307\u4ee3reverse\uff0c\u8fd9\u91cc\u662f\u6307\u53cd\u5411\u6bd4\u8f83\u7ed3\u679c\uff0c\u8f93\u51fa\u65f6\u9ed8\u8ba4\u4ece\u5c0f\u5230\u5927\uff0c\u53cd\u5411\u540e\u4ece\u5927\u5230\u5c0f\u3002\uff09\u3002\u672c\u4f8b\u4e2d\uff0c\u53ef\u4ee5\u770b\u5230%MEM\u5728\u7b2c4\u4e2a\u4f4d\u7f6e\uff0c\u6839\u636e%MEM\u7684\u6570\u503c\u8fdb\u884c\u7531\u5927\u5230\u5c0f\u7684\u6392\u5e8f\u3002<\/p>\n<p>head -K\uff08K\u6307\u4ee3\u884c\u6570\uff0c\u5373\u8f93\u51fa\u524d\u51e0\u4f4d\u7684\u7ed3\u679c\uff09<\/p>\n<p>|\u4e3a\u7ba1\u9053\u7b26\u53f7\uff0c\u5c06\u67e5\u8be2\u51fa\u7684\u7ed3\u679c\u5bfc\u5230\u4e0b\u9762\u7684\u547d\u4ee4\u4e2d\u8fdb\u884c\u4e0b\u4e00\u6b65\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u65b9\u6cd52\uff1atop\u00a0\uff08\u7136\u540e\u6309\u4e0bM\uff0c\u6ce8\u610f\u5927\u5199\uff09<\/p>\n<p>\u4e8c\u3001\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u67e5\u4f7f\u7528CPU\u6700\u591a\u7684K\u4e2a\u8fdb\u7a0b<\/p>\n<p>\u65b9\u6cd51\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>ps -aux | sort -k3nr | head -K<\/pre>\n<\/div>\n<p>\u65b9\u6cd52\uff1atop\u00a0\uff08\u7136\u540e\u6309\u4e0bP\uff0c\u6ce8\u610f\u5927\u5199<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521b\u5efa\u811a\u672ccleancache.sh #!\/bin\/bash sync echo 1 &gt; \/proc\/sy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,21],"tags":[471,280,281,279,353,198],"class_list":["post-782","post","type-post","status-publish","format-standard","hentry","category-linux","category-script","tag-js-bat","tag-linux"],"_links":{"self":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=782"}],"version-history":[{"count":0,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/782\/revisions"}],"wp:attachment":[{"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}