{"id":253190,"date":"2022-09-25T09:43:31","date_gmt":"2022-09-25T01:43:31","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=253190"},"modified":"2022-09-21T14:44:20","modified_gmt":"2022-09-21T06:44:20","slug":"linux-press-kill","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-press-kill.html","title":{"rendered":"\u4f60\u662f\u600e\u4e48\u5728 Linux \u5e72\u6389\u8fdb\u7a0b\u7684?"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5982\u679c\u8fdb\u7a0b\u5728\u524d\u53f0\u8fd0\u884c,\u4f60\u53ef\u4ee5\u4f7f\u7528 Ctrl+C \u7ec8\u7aef\u5feb\u6377\u65b9\u5f0f\u3002\u4f46\u662f,\u5982\u679c\u8fdb\u7a0b\u4e0d\u53ef\u89c1(\u5728\u540e\u53f0\u8fd0\u884c),\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e13\u7528\u547d\u4ee4\u6740\u6b7b\u5b83\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/a><\/p>\n

\u7ec8\u6b62\u8fdb\u7a0b\u662f\u6307\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u505c\u6b62\u8fdb\u7a0b\u3002\u5982\u679c\u4f60\u77e5\u9053\u8fdb\u7a0bID(PID)\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528 kill \u547d\u4ee4\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n

 > kill<\/span> <signal> <PID><\/pre>\n

\u5728\u4e0a\u9762\u7684\u8bed\u6cd5\u4e2d\uff0csignal\u6307\u7684\u662f\u8981\u53d1\u9001\u7ec8\u6b62\u7684\u7ec8\u6b62\u4fe1\u53f7\uff0c\u5e76\u4e14PID\u6307\u7684\u662f\u8fdb\u7a0b\u7684 ID\u3002
\n\u8fd8\u6709\u4e00\u4e2a killall \u547d\u4ee4\uff0c\u6211\u5c06\u5728\u672c\u6587\u4e2d\u8ba8\u8bbakill \u548c killall \u547d\u4ee4\u3002<\/p>\n

Linux \u4e2d\u7684\u7ec8\u6b62\u4fe1\u53f7<\/strong><\/div>\n

\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u88ab\u64cd\u4f5c\u7cfb\u7edf\u6216\u7528\u6237\u7ec8\u6b62\u65f6\uff0c\u5373\u8fdb\u7a0b\u6ca1\u6709\u81ea\u884c\u5b8c\u6210,\u5b83\u4f1a\u88ab\u53d1\u9001\u4e00\u4e2a\u7ec8\u7aef\u4fe1\u53f7\u3002<\/p>\n

\u4ee5\u4e0b\u662f\u53ef\u7528\u7684\u7ec8\u6b62\u4fe1\u53f7:<\/strong><\/span><\/div>\n

\"\"<\/a><\/p>\n

\u5e38\u7528\u7684\u4fe1\u53f7 9 \u548c 15<\/strong><\/span><\/div>\n
\u83b7\u53d6\u8fdb\u7a0b\u7684PID<\/strong><\/div>\n

\u4f60\u8fd8\u9700\u8981\u4e86\u89e3\u8981\u7ec8\u6b62\u7684\u8fdb\u7a0b\u7684\u8be6\u7ec6\u4fe1\u606f\u3002\u4f7f\u7528 kill \u547d\u4ee4,\u4f60\u5fc5\u987b\u63d0\u4f9b\u8fdb\u7a0b\u7684 ID(PID)\u3002\u4f60\u53ef\u4ee5\u4ece\u8fdb\u7a0b\u540d\u79f0\u4e2d\u83b7\u53d6 PID<\/p>\n

> pidof exact_process_name<\/pre>\n

\u6bd4\u5982\u83b7\u53d6java\u8fdb\u7a0b\u7684\u8fdb\u7a0b\u53f7<\/p>\n

> pidof java\r\n8075 1032\r\n<\/pre>\n
\u5728 Linux \u547d\u4ee4\u884c\u4e2d\u7ec8\u6b62\u8fdb\u7a0b<\/strong><\/div>\n
\u4f7f\u7528 kill \u547d\u4ee4<\/strong><\/span><\/div>\n

\u8be5kill\u547d\u4ee4\u8981\u6c42\u4f60\u77e5\u9053\u8981\u7ec8\u6b62\u7684\u8fdb\u7a0b\u7684 ID\uff0c\u4ee5\u53ca\u53ef\u9009\u7684\u7ec8\u6b62\u4fe1\u53f7\u3002
\n\u8981\u7b80\u5355\u5730\u7ec8\u6b62\u547d\u4ee4\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n

kill [signal] \r\n<\/pre>\n

\u5411 PID \u53d1\u9001\u7ec8\u6b62\u4fe1\u53f7\u662f\u53ef\u9009\u7684\uff0c\u5982\u679c\u672a\u63d0\u4f9b\u4efb\u4f55\u4fe1\u53f7\uff0c\u5219kill\u9ed8\u8ba4\u53d1\u9001 SIGTERM ( 15)\uff0c\u4ee5\u6b63\u5e38\u7ec8\u6b62\u6240\u8ff0\u8fdb\u7a0b\u7ed3\u675f\u3002
\n\u6211\u542f\u52a8\u4e86sleep \u547d\u4ee4\u7684\u540e\u53f0\u8fdb\u7a0b\uff08\u5b83\u7ed9\u4e86\u6211\u4e00\u4e2a PID\uff09\u3002\u6211\u4eec\u4f7f\u7528kill\u547d\u4ee4\u6740\u6b7b\u5b83\u3002
\n\u6740\u6b7b\u8fd9\u4e2a\u7279\u5b9a\u7684\u5b9e\u4f8bsleep\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

$  sleep 120 &\r\n[1] 125686\r\n$ kill 125686\r\n[1]  + terminated  sleep 120\r\n<\/pre>\n

\u5982\u679c\u6211\u60f3\u4f7f\u7528\u7ec8\u6b62\u4fe1\u53f7\uff0c\u6211\u53ef\u4ee5\u4f7f\u7528\u6570\u503c\u6216\u4fe1\u53f7\u672c\u8eab\uff1a<\/p>\n

$ sleep 120 &\r\n[1] 125746\r\n$ kill -SIGKILL 125746\r\n[1]  + killed     sleep 120\r\n$ sleep 120 &\r\n[1] 125759\r\n$ kill -9 125759\r\n[1]  + killed     sleep 120\r\n<\/pre>\n

\u5982\u679c kill \u547d\u4ee4\u6ca1\u6709\u6307\u5b9a\u4fe1\u53f7\uff0c\u5219\u9ed8\u8ba4\u4f7f\u7528 SIGTERM (15)\u3002<\/p>\n

\u4f7f\u7528 killall \u547d\u4ee4<\/strong><\/span><\/div>\n

\u5982\u679c\u4e0d\u77e5\u9053\u67d0\u4e2a\u8fdb\u7a0b\u7684PID\u662f\u591a\u5c11\uff0c\u6216\u8005\u8be5\u8fdb\u7a0b\u6709\u591a\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u53c8\u60f3\u4e00\u6b21\u6027\u6740\u6b7b\u5b50\u8fdb\u7a0b\u548c\u7236\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u4f7f\u7528killall\u547d\u4ee4\u3002<\/p>\n

killall [signal] \r\n<\/pre>\n

\u4e0ekill\u547d\u4ee4\u7c7b\u4f3c\uff0c\u6307\u5b9a\u7ec8\u6b62\u4fe1\u53f7\u662f\u53ef\u9009\u7684\u3002\u5f53\u6ca1\u6709\u6307\u5b9a\u7ec8\u6b62\u4fe1\u53f7\u65f6\uff0ckillall\u5c06\u53d1\u9001 SIGTERM ( 15) \u4ee5\u4f18\u96c5\u5730\u5173\u95ed\u6240\u8ff0\u8fdb\u7a0b\u3002<\/p>\n

\u4e3a\u4e86\u6f14\u793akillall\u7684\u4f7f\u7528\uff0c\u6211\u5c06\u6740\u6b7b\u4e24\u4e2a\u6b63\u5728\u8fd0\u884c\u7684 sleep \u547d\u4ee4\u3002<\/p>\n

$ sleep 120 &\r\n[1] 112351\r\n$ sleep 2000 &\r\n[2] 112362\r\n$ killall sleep\r\n[1]-  Terminated              sleep 120\r\n[2]+  Terminated              sleep 2000\r\n<\/pre>\n

\u6b64\u5916\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8be5-e\u6807\u5fd7\u6765\u67e5\u627e\u8fdb\u7a0b\u540d\u79f0\u7684\u5b8c\u5168\u5339\u914d\u3002<\/p>\n

\u4f7f\u7528 pkill \u547d\u4ee4<\/strong><\/span><\/div>\n

\u547d\u4ee4\u7684\u66ff\u4ee3\u547d\u4ee4kill\u662fpkill\u547d\u4ee4\u3002\u5b83\u662fpgrep\u548ckill\u547d\u4ee4\u7684\u7ec4\u5408\u3002
\nkillall\u6740\u6b7b\u6240\u6709\u5177\u6709\u5339\u914d\u540d\u79f0\u7684\u8fdb\u7a0b\u3002\u53e6\u4e00\u65b9\u9762\uff0cpkill\u4f7f\u7528\u6a21\u5f0f\u5339\u914d\u6765\u5339\u914d\u8fdb\u7a0b\u5e76\u6740\u6b7b\u5b83\u4eec\u3002<\/p>\n

pkill [options] pattern\r\n<\/pre>\n

\u547d\u4ee4\u4e2d\u53ef\u7528\u7684\u4e00\u4e9b\u6709\u7528\u9009\u9879pkill\u5982\u4e0b\uff1a<\/p>\n

    \n
  1. -u: \u7279\u5b9a\u6240\u6709\u8005\u62e5\u6709\u7684\u8fdb\u7a0b<\/li>\n
  2. -x: \u5b8c\u5168\u5339\u914d\u6a21\u5f0f\u7684\u8fdb\u7a0b<\/li>\n
  3. -signal: \u6307\u5b9a\u7ec8\u6b62\u4fe1\u53f7\uff08\u9ed8\u8ba4\u4e3a SIGTERM\uff09<\/li>\n<\/ol>\n

    \u7ed3\u675fnginx\u8fdb\u7a0b<\/p>\n

    > pkill nginx<\/pre>\n","protected":false},"excerpt":{"rendered":"

    \u7ec8\u6b62\u8fdb\u7a0b\u662f\u6307\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u505c\u6b62\u8fdb\u7a0b\u3002\u5982\u679c\u4f60\u77e5\u9053\u8fdb\u7a0bID(PID)\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528 kill \u547d\u4ee4\uff0c\u5982\u4e0b\u6240\u793a: &gt […]<\/p>\n","protected":false},"author":643,"featured_media":253205,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-253190","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\/253190","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=253190"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/253190\/revisions"}],"predecessor-version":[{"id":253195,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/253190\/revisions\/253195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/253205"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=253190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=253190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=253190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}