{"id":116834,"date":"2018-08-30T08:19:36","date_gmt":"2018-08-30T00:19:36","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=116834"},"modified":"2018-08-24T09:21:00","modified_gmt":"2018-08-24T01:21:00","slug":"pgrep-grep-ps","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/pgrep-grep-ps.html","title":{"rendered":"\u5982\u4f55\u4f7f\u7528pgrep\u5339\u914d"},"content":{"rendered":"

\u5728linux\u4e2d\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\uff0c\u7ecf\u5e38\u8981\u7528\u5230pa auxf\uff0c\u5177\u4f53\u5230\u67d0\u4e2a\u8fdb\u7a0b\u7684\u65f6\u5019\uff0c\u53c8\u9700\u8fdb\u884cgrep\u7ba1\u9053\u3002\u5982\uff1aps auxf|grep java|grep -v grep \uff0c\u5373\u7136\u8fd9\u4e48\u957f\uff0c\u53ef\u4ee5\u4e0d\u53ef\u4ee5\u7b80\u5316\u5462\uff1f\u5f53\u7136\u53ef\u4ee5\uff0c\u5982\u679c\u8fd8\u662f\u4f7f\u7528ps\u547d\u4ee4\u7684\u8bdd\uff0c\u53ef\u4ee5\u6539\u4e3aps auxf|grep jav[a]\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528\u6392\u9664\u81ea\u8eab\u4e86\u3002\u4e0d\u8fc7\u611f\u89c9\u547d\u4ee4\u8fd8\u662f\u957f\u4e86\u70b9\uff0c\u80fd\u4e0d\u80fd\u518d\u7b80\u70b9\uff0c\u53ef\u4ee5\uff0c\u4f7f\u7528pgrep java \uff0c\u4e0d\u8fc7\u6b64\u65f6\u5f97\u51fa\u7684\u53ea\u662fpid \u3002pgrep\u547d\u4ee4\u76f8\u5f53\u4e8e\u5982\u4e0b\u7684\u547d\u4ee4\uff1a<\/p>\n

ps -eo pid,cmd | awk '{print $1,$2}' | grep KeyWord\r\n<\/pre>\n
\u53c2\u6570\u8bf4\u660e\uff1a<\/strong><\/span><\/div>\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\u9009\u9879<\/td>\n\u8bf4\u660e<\/td>\n<\/tr>\n
-d<\/td>\n\u5b9a\u4e49\u591a\u4e2a\u8fdb\u7a0b\u4e4b\u95f4\u7684\u5206\u9694\u7b26, \u5982\u679c\u4e0d\u5b9a\u4e49\u5219\u4f7f\u7528\u6362\u884c\u7b26\u3002<\/td>\n<\/tr>\n
-P<\/td>\n\u6839\u636e\u7236\u8fdb\u7a0bPID\uff0c\u627e\u51fa\u6240\u6709\u5b57\u8fdb\u7a0b\u7684pid<\/td>\n<\/tr>\n
-n<\/td>\n\u8868\u793a\u5982\u679c\u8be5\u7a0b\u5e8f\u6709\u591a\u4e2a\u8fdb\u7a0b\u6b63\u5728\u8fd0\u884c\uff0c\u5219\u4ec5\u67e5\u627e\u6700\u65b0\u7684\uff0c\u5373\u6700\u540e\u542f\u52a8\u7684\u3002<\/td>\n<\/tr>\n
-o<\/td>\n\u8868\u793a\u5982\u679c\u8be5\u7a0b\u5e8f\u6709\u591a\u4e2a\u8fdb\u7a0b\u6b63\u5728\u8fd0\u884c\uff0c\u5219\u4ec5\u67e5\u627e\u6700\u8001\u7684\uff0c\u5373\u6700\u5148\u542f\u52a8\u7684\uff08\u591a\u4e2a\u8fdb\u7a0b\u65f6\u5373\u7236\u8fdb\u7a0bPID\uff09\u3002<\/td>\n<\/tr>\n
-G<\/td>\n\u5176\u540e\u8ddf\u7740\u4e00\u7ec4group id\uff0c\u8be5\u547d\u4ee4\u5728\u641c\u7d22\u65f6\uff0c\u4ec5\u8003\u8651group\u5217\u8868\u4e2d\u7684\u8fdb\u7a0b\u3002<\/td>\n<\/tr>\n
-u<\/td>\n\u5176\u540e\u8ddf\u7740\u4e00\u7ec4\u6709\u6548\u7528\u6237ID(effetive user id)\uff0c\u8be5\u547d\u4ee4\u5728\u641c\u7d22\u65f6\uff0c\u4ec5\u8003\u8651\u8be5effective user\u5217\u8868\u4e2d\u7684\u8fdb\u7a0b\u3002<\/td>\n<\/tr>\n
-U<\/td>\n\u5176\u540e\u8ddf\u7740\u4e00\u7ec4\u5b9e\u9645\u7528\u6237ID(real user id)\uff0c\u8be5\u547d\u4ee4\u5728\u641c\u7d22\u65f6\uff0c\u4ec5\u8003\u8651\u8be5real user\u5217\u8868\u4e2d\u7684\u8fdb\u7a0b\u3002<\/td>\n<\/tr>\n
-x<\/td>\n\u8868\u793a\u8fdb\u7a0b\u7684\u540d\u5b57\u5fc5\u987b\u5b8c\u5168\u5339\u914d, \u4ee5\u4e0a\u7684\u9009\u9879\u5747\u53ef\u4ee5\u90e8\u5206\u5339\u914d\u3002<\/td>\n<\/tr>\n
-l<\/td>\n\u5c06\u4e0d\u4ec5\u6253\u5370pid,\u4e5f\u6253\u5370\u8fdb\u7a0b\u540d\u3002<\/td>\n<\/tr>\n
-f<\/td>\n\u4e00\u822c\u4e0e-l\u5408\u7528, \u5c06\u6253\u5370\u8fdb\u7a0b\u7684\u53c2\u6570\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u4f7f\u7528\u793a\u4f8b<\/strong><\/span><\/div>\n
\u9ed8\u8ba4\u53ea\u663e\u793aPID\r\nroot@361way:~# pgrep zabbix\r\n2380\r\n2381\r\n2382\r\n2383\r\n2384\r\n2385\r\n-l \u540c\u65f6\u663e\u793aPID\u548cProcessName\r\nroot@361way:~# pgrep -l zabbix\r\n2380 zabbix_agentd\r\n2381 zabbix_agentd\r\n2382 zabbix_agentd\r\n2383 zabbix_agentd\r\n2384 zabbix_agentd\r\n2385 zabbix_agentd\r\n-o \u5f53\u5339\u914d\u591a\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u663e\u793a\u8fdb\u7a0b\u53f7\u6700\u5c0f\u7684\u90a3\u4e2a\r\nroot@361way:~# pgrep -l -o zabbix\r\n2380 zabbix_agentd\r\n-n \u5f53\u5339\u914d\u591a\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u663e\u793a\u8fdb\u7a0b\u53f7\u6700\u5927\u7684\u90a3\u4e2a\r\nroot@361way:~# pgrep -l -n zabbix\r\n2385 zabbix_agentd\r\n<\/pre>\n

\u8fd9\u91cc\u9700\u8981\u7279\u522b\u6307\u51fa\u7684\u662fpgrep\u9ed8\u8ba4\u53ea\u80fd\u5339\u914d\u8fdb\u7a0b\u7684\u524d15\u4e2a\u5b57\u7b26\u4e32\uff0c\u4e2a\u4f53\u53ef\u4ee5\u53c2\u770bubuntu\u95ee\u7b54\u4e0a\u7684\u8bf4\u660e\uff0c\u5982\u4e0b\uff1a<\/p>\n

ps aux includes the full command line (path and parameters),\r\nwhile pgrep only looks at the first 15 characters of the executable's names\r\n<\/pre>\n
\u7279\u6b8a\u53c2\u6570<<\/strong><\/span><\/div>\n

\u4f7f\u7528pgrep -f \u53ef\u4ee5\u8fdb\u884c\u8fdb\u7a0b\u5168\u5b57\u7b26\u5339\u914d\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n

\/\/\u4f7f\u7528ps\u547d\u4ee4\u53ef\u4ee5\u6b63\u5e38grep\u5230\u8fdb\u7a0b\r\nroot@361way:~# ps auxf|grep druid\r\nroot 25713 0.0 0.0 8108 940 pts\/0 S+ 06:08 0:00 _ grep --color=auto druid\r\ndev 7438 1.3 11.5 5524888 884988 ? Sl Jun16 672:54 java -server -Xmx4g -XX:MaxNewSize=1g -XX:+UseCompressedOops -XX:+UseParNewGC -Duser.timezone=UTC -Dfile.encoding=UTF-8 -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCMSInitiatingOccupancyOnly -XX:+PrintHeapAtGC -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime -Djava.io.tmpdir=\/data\/tmpdata\/java.io.tmpdata -Xloggc:\/data\/tmpdata\/java.io.tmpdata\/coordinator-gc.log -classpath lib\/*:config\/coordinator io.druid.cli.Main server coordinator\r\n\/\/pgrep\u7684\u5339\u914d\u7ed3\u679c\u4e3a\u7a7a\r\nroot@361way:~# pgrep druid\r\n\/\/\u52a0\u4e0a-f\u53c2\u6570\u540e\uff0c\u6b63\u5e38\u5f97\u5230\u8fdb\u7a0bpid\r\nroot@361way:~# pgrep -f druid\r\n7438\r\nroot@361way:~# pgrep -f -l druid\r\n7438 java -server -Xmx4g -XX:MaxNewSize=1g -XX:+UseCompressedOops -XX:+UseParNewGC -Duser.timezone=UTC -Dfile.encoding=UTF-8 -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCMSInitiatingOccupancyOnly -XX:+PrintHeapAtGC -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime -Djava.io.tmpdir=\/data\/tmpdata\/java.io.tmpdata -Xloggc:\/data\/tmpdata\/java.io.tmpdata\/coordinator-gc.log -classpath lib\/*:config\/coordinator io.druid.cli.Main server coordinator\r\n<\/pre>\n

\u4f7f\u7528 -P \u53c2\u6570\u53ef\u4ee5\u8f93\u51fa\u6307\u5b9a\u7236\u8fdb\u7a0b\u7684\u5b50\u8fdb\u7a0b\uff0c\u5982\uff1a<\/p>\n

root@361way:~# pgrep -P 2380\r\n2381\r\n2382\r\n2383\r\n2384\r\n2385\r\n<\/pre>\n

\u76f8\u5173\u547d\u4ee4pkill\u00a0\uff0c\u7528\u6cd5\u57fa\u672c\u548cpgrep\u4e00\u81f4\u3002<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.361way.com\/pgrep\/3650.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttps:\/\/lrxjmw.cn\/pgrep-grep-ps.html<\/a>\u7f16\u8f91\uff1a\u5f20\u96c4\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5728linux\u4e2d\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\uff0c\u7ecf\u5e38\u8981\u7528\u5230pa auxf\uff0c\u5177\u4f53\u5230\u67d0\u4e2a\u8fdb\u7a0b\u7684\u65f6\u5019\uff0c\u53c8\u9700\u8fdb\u884cgrep\u7ba1\u9053\u3002\u5982\uff1aps a […]<\/p>\n","protected":false},"author":643,"featured_media":116845,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-116834","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/116834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=116834"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/116834\/revisions"}],"predecessor-version":[{"id":117040,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/116834\/revisions\/117040"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/116845"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=116834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=116834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=116834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}