{"id":13474,"date":"2024-08-01T13:49:41","date_gmt":"2024-08-01T05:49:41","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=13474"},"modified":"2024-08-01T13:49:40","modified_gmt":"2024-08-01T05:49:40","slug":"%e4%bd%bf%e7%94%a8-jvm-%e5%91%bd%e4%bb%a4%e6%8a%a5%e9%94%99%ef%bc%9a-cant-attach-to-the-process","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=13474","title":{"rendered":"\u4f7f\u7528 JVM \u547d\u4ee4\u62a5\u9519\uff1a Can&#8217;t attach to the process"},"content":{"rendered":"<h3>\u6982\u8981\u63cf\u8ff0<\/h3>\n<p>\u65e5\u5e38\u6392\u67e5\u95ee\u9898\u65f6\uff0c\u7ecf\u5e38\u4f1a\u7528\u5230JVM\u5185\u5b58\u5206\u6790\u76f8\u5173\u7684\u547d\u4ee4\uff0c\u5982\uff1ajps\uff0cjstat\uff0cjmap\uff0cjstack\uff0cjinfo\u7b49\uff0c\u5177\u4f53\u7528\u6cd5\u53c2\u8003KB\uff1a<a href=\"https:\/\/kb.transwarp.cn\/posts\/1088\" title=\"JVM\u7684\u5185\u5b58\u5206\u6790\u547d\u4ee4\u89e3\u6790\">JVM\u7684\u5185\u5b58\u5206\u6790\u547d\u4ee4\u89e3\u6790<\/a><\/p>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<hr \/>\n<h4>\u95ee\u9898\u73b0\u8c61<\/h4>\n<p>\u4f7f\u7528jvm\u547d\u4ee4\u65f6\u62a5\u9519\uff1aCan&#8217;t attach to the process\uff0c\u5982\u56fe\u6267\u884c <strong>jinfo pid<\/strong> \u62a5\u9519\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/nj.transwarp.cn:8180\/wp-content\/uploads\/2024\/07\/image-1719909513985.png\" alt=\"file\" \/><\/p>\n<h4>\u89e3\u51b3\u65b9\u6848<\/h4>\n<p>\u5148\u6267\u884c<\/p>\n<pre><code class=\"language-shell\">echo 0 > \/proc\/sys\/kernel\/yama\/ptrace_scope<\/code><\/pre>\n<p>\u518d\u91cd\u65b0\u6267\u884c\u547d\u4ee4\u5373\u53ef\uff0c\u5982\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/nj.transwarp.cn:8180\/wp-content\/uploads\/2024\/07\/image-1719909623100.png\" alt=\"file\" \/><\/p>\n<h4>\u539f\u56e0<\/h4>\n<h5>\u539f\u7406<\/h5>\n<p>ptrace-scope \u662f Linux \u5185\u6838\u4e2d\u7684\u4e00\u4e2a\u5b89\u5168\u673a\u5236\uff0c\u5b83\u4e0e Yama Linux \u5b89\u5168\u6a21\u5757\u76f8\u5173\u8054\uff0c\u7528\u4e8e\u9650\u5236\u8fdb\u7a0b\u95f4\u7684 ptrace \u8c03\u7528\u3002<br \/>\nptrace \u662f Linux \u7cfb\u7edf\u4e2d\u7684\u4e00\u4e2a\u7cfb\u7edf\u8c03\u7528\uff0c\u5141\u8bb8\u4e00\u4e2a\u8fdb\u7a0b\uff08\u8ffd\u8e2a\u8005\uff09\u9644\u52a0\u5230\u53e6\u4e00\u4e2a\u8fdb\u7a0b\uff08\u88ab\u8ffd\u8e2a\u8005\uff09\u4e0a\uff0c\u4ee5\u68c0\u67e5\u548c\u63a7\u5236\u5176\u6267\u884c\u3002\u8fd9\u79cd\u80fd\u529b\u5982\u679c\u88ab\u6ee5\u7528\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5b89\u5168\u95ee\u9898\uff0c\u4f8b\u5982\u5141\u8bb8\u653b\u51fb\u8005\u9644\u52a0\u5230\u5176\u4ed6\u7528\u6237\u7684\u8fdb\u7a0b\u5e76\u7a83\u53d6\u654f\u611f\u4fe1\u606f\u3002<\/p>\n<p>ptrace-scope \u7684\u503c\u53ef\u4ee5\u901a\u8fc7 \/proc\/sys\/kernel\/yama\/ptrace_scope \u6587\u4ef6\u8fdb\u884c\u914d\u7f6e\uff0c\u5e76\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u4ee5\u4e0b\u51e0\u79cd\u6a21\u5f0f\uff1a<\/p>\n<p><strong>0<\/strong>: \u65e0\u9650\u5236\uff0c\u8fdb\u7a0b\u53ef\u4ee5\u9644\u52a0\u5230\u4efb\u4f55\u5176\u4ed6\u8fdb\u7a0b\u4e0a\u3002<\/p>\n<p><strong>1<\/strong>: \u9650\u5236\u9644\u52a0\uff0c\u53ea\u6709\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\u53ef\u4ee5\u9644\u52a0\uff1a<\/p>\n<ul>\n<li>\u7236\u8fdb\u7a0b\u6216\u5176\u540e\u4ee3\u3002<\/li>\n<li>\u5177\u6709 CAP_SYS_PTRACE \u80fd\u529b\uff08\u7cfb\u7edf\u7ba1\u7406\u5458\u6743\u9650\uff09\u7684\u8fdb\u7a0b\u3002<\/li>\n<li>\u88ab\u8ffd\u8e2a\u8fdb\u7a0b\u901a\u8fc7 PR_SET_PTRACER \u660e\u786e\u5141\u8bb8\u7684\u8fdb\u7a0b\u3002<\/li>\n<\/ul>\n<p><strong>2<\/strong>: \u53ea\u6709\u5177\u6709 CAP_SYS_PTRACE \u80fd\u529b\u7684\u8fdb\u7a0b\u624d\u80fd\u9644\u52a0\uff0c\u4e14\u8fd9\u4e9b\u8fdb\u7a0b\u5fc5\u987b\u5728\u88ab\u8ffd\u8e2a\u8fdb\u7a0b\u7684\u7528\u6237\u547d\u540d\u7a7a\u95f4\u4e2d\u3002<\/p>\n<p><strong>3<\/strong>: \u5b8c\u5168\u7981\u6b62\u9644\u52a0\u3002<\/p>\n<h5>\u53c2\u6570\u4fee\u6539<\/h5>\n<p>1\uff09\u8be5\u53c2\u6570\u53ef\u4ee5\u4e34\u65f6\u5f00\u542f\uff0c\u5982:<\/p>\n<pre><code class=\"language-shell\">echo 0 > \/proc\/sys\/kernel\/yama\/ptrace_scope<\/code><\/pre>\n<p>2\uff09\u4e5f\u6c38\u4e45\u5199\u5230\u6587\u4ef6\u6765\u6301\u4e45\u5316\uff0c\u5982\uff1a<br \/>\n\u7f16\u8f91 \/etc\/sysctl.d\/10-ptrace.conf<\/p>\n<p>\u6dfb\u52a0\u6216\u4fee\u6539:(0:\u5141\u8bb8, 1:\u4e0d\u5141\u8bb8)<\/p>\n<pre><code class=\"language-shell\">kernel.yama.ptrace_scope = 0<\/code><\/pre>\n<p>\u6267\u884c\u751f\u6548\uff1a<\/p>\n<pre><code class=\"language-shell\">sysctl -p \/etc\/sysctl.d\/10-ptrace.conf<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981\u63cf\u8ff0 \u65e5\u5e38\u6392\u67e5\u95ee\u9898\u65f6\uff0c\u7ecf\u5e38\u4f1a\u7528\u5230JVM\u5185\u5b58\u5206\u6790\u76f8\u5173\u7684\u547d\u4ee4\uff0c\u5982\uff1ajps\uff0cjstat\uff0cjmap\uff0cjstack\uff0c ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=13474\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":105,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13474","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/13474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/users\/105"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13474"}],"version-history":[{"count":3,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/13474\/revisions"}],"predecessor-version":[{"id":13761,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/13474\/revisions\/13761"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}