<script type="application/ld+json">{"@context":"http://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://www.simcentric.com/tc/"},{"@type":"ListItem","position":2,"name":"如何使用 strace 追蹤程序的系統呼叫","item":"https://www.simcentric.com/hong-kong-dedicated-server/how-to-use-strace-to-trace-system-calls-of-a-process/"}]}</script> {"id":35223,"date":"2026-10-18T08:00:33","date_gmt":"2026-10-18T00:00:33","guid":{"rendered":"https:\/\/www.simcentric.com\/uncategorized-tc\/how-to-use-strace-to-trace-system-calls-of-a-process\/"},"modified":"2026-10-16T10:31:04","modified_gmt":"2026-10-16T02:31:04","slug":"how-to-use-strace-to-trace-system-calls-of-a-process","status":"publish","type":"post","link":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/how-to-use-strace-to-trace-system-calls-of-a-process\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 strace \u8ffd\u8e64\u7a0b\u5e8f\u7684\u7cfb\u7d71\u547c\u53eb"},"content":{"rendered":"<p>Strace \u662f\u4e00\u6b3e Linux \u547d\u4ee4\u5217\u5de5\u5177\uff0c\u5b83\u85c9\u52a9 <code>ptrace()<\/code> \u7cfb\u7d71\u547c\u53eb\u5373\u6642\u6514\u622a\u7cfb\u7d71\u547c\u53eb\u8207\u8a0a\u865f\uff0c\u80fd\u5920\u7cbe\u78ba\u5c55\u793a\u4e00\u500b\u7a0b\u5e8f\u5728\u4f3a\u670d\u5668\u4e0a\u7684\u5be6\u969b\u884c\u70ba\u3002\u56e0\u6b64\uff0cstrace \u662f\u9664\u932f\u8207\u6545\u969c\u6392\u9664\u3001\u6548\u80fd\u8abf\u6821\u4ee5\u53ca\u5b89\u5168\u5206\u6790\u4e2d\u7684\u91cd\u8981\u5de5\u5177\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 strace \u4f86\u8ffd\u8e64\u7cfb\u7d71\u547c\u53eb\uff0c\u5f9e\u57fa\u790e\u547d\u4ee4\u5230\u9032\u968e\u8f38\u51fa\u7ba1\u7406\u90fd\u80fd\u6db5\u84cb\u3002\u7576\u4f60\u5728 <a href=\"https:\/\/www.simcentric.com\/tc\/products\/dedicated-server-hk\/\" target=\"_blank\" rel=\"noopener\">Linux \u4f3a\u670d\u5668<\/a>\u4e0a\u9664\u932f\u61c9\u7528\u7a0b\u5f0f\u6642\uff0cstrace \u80fd\u986f\u793a\u6bcf\u4e00\u6b21\u6a94\u6848\u958b\u555f\u3001\u7db2\u8def\u8b80\u53d6\u8207<a href=\"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-is-the-memory-wall-for-hong-kong-servers\/\" target=\"_blank\" rel=\"noopener\">\u8a18\u61b6\u9ad4\u914d\u7f6e<\/a>\u3002\u9019\u7a2e\u53ef\u898b\u6027\u8b93\u6392\u969c\u5f9e\u300c\u731c\u6e2c\u300d\u8b8a\u6210\u300c\u7cbe\u6e96\u8a3a\u65b7\u300d\u3002\u4f60\u5c07\u5b78\u6703\u5982\u4f55\u5728\u4e0d\u91cd\u65b0\u555f\u52d5\u670d\u52d9\u7684\u60c5\u6cc1\u4e0b\uff0c\u5c0d\u6b63\u5728\u57f7\u884c\u7684\u670d\u52d9\u9032\u884c\u7cfb\u7d71\u547c\u53eb\u8ffd\u8e64\u3002<\/p>\n<h2><strong>\u5982\u4f55\u4f7f\u7528 strace \u8ffd\u8e64\u7cfb\u7d71\u547c\u53eb<\/strong><\/h2>\n<h3>\u8ffd\u8e64\u67d0\u500b\u547d\u4ee4\u767c\u8d77\u7684\u7cfb\u7d71\u547c\u53eb<\/h3>\n<p>\u4f7f\u7528 strace \u8ffd\u8e64\u7cfb\u7d71\u547c\u53eb\u6700\u7c21\u55ae\u7684\u65b9\u6cd5\uff0c\u5c31\u662f\u76f4\u63a5\u900f\u904e\u5b83\u4f86\u57f7\u884c\u76ee\u6a19\u547d\u4ee4\u3002\u4f60\u53ea\u9700\u8f38\u5165 <code>strace<\/code>\uff0c\u5f8c\u9762\u63a5\u4e0a\u4f60\u60f3\u89c0\u5bdf\u7684\u547d\u4ee4\u3002\u4f8b\u5982\uff0c<code>strace ls -l<\/code> \u6703\u5728\u57f7\u884c <code>ls<\/code> \u547d\u4ee4\u7684\u540c\u6642\uff0c\u64f7\u53d6\u5b83\u767c\u8d77\u7684\u6bcf\u4e00\u6b21\u7cfb\u7d71\u547c\u53eb\u3002\u8a72\u5de5\u5177\u6703\u8a18\u9304\u7a0b\u5f0f\u8207 Linux \u6838\u5fc3\u4e4b\u9593\u7684\u6bcf\u4e00\u6b21\u4e92\u52d5\u3002\u4f60\u53ef\u4ee5\u770b\u5230\u6a94\u6848\u958b\u555f\u3001\u76ee\u9304\u8b80\u53d6\u3001\u8a18\u61b6\u9ad4\u6620\u5c04\u4ee5\u53ca\u7a0b\u5e8f\u7d50\u675f\u7b49\u64cd\u4f5c\u3002\u9019\u7a2e\u65b9\u5f0f\u975e\u5e38\u9069\u5408\u90a3\u4e9b\u751f\u547d\u9031\u671f\u8f03\u77ed\u3001\u5e0c\u671b\u7acb\u5373\u770b\u5230\u7d50\u679c\u7684\u547d\u4ee4\u3002<\/p>\n<p>\u5176\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<code>strace \/path\/to\/program<\/code>\u3002\u4f60\u53ef\u4ee5\u7528\u9019\u7a2e\u65b9\u5f0f\u8ffd\u8e64\u4efb\u4f55\u53ef\u57f7\u884c\u6a94\u3002\u57f7\u884c\u8a72\u547d\u4ee4\u5f8c\uff0cstrace \u6703\u5c07\u76ee\u6a19\u7a0b\u5f0f\u4f5c\u70ba\u5b50\u7a0b\u5e8f\u555f\u52d5\uff0c\u4e26\u6514\u622a\u7a0b\u5f0f\u9001\u7d66\u6838\u5fc3\u7684\u6bcf\u4e00\u500b\u8acb\u6c42\u3002\u8f38\u51fa\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u6703\u986f\u793a\u7cfb\u7d71\u547c\u53eb\u540d\u7a31\u3001\u53c3\u6578\u4ee5\u53ca\u56de\u50b3\u503c\u3002\u9019\u4e9b\u8f38\u51fa\u80fd\u5e6b\u52a9\u4f60\u5b8c\u6574\u4e86\u89e3\u7a0b\u5f0f\u7684\u57f7\u884c\u884c\u70ba\u3002\u4f60\u53ef\u4ee5\u85c9\u6b64\u767c\u73fe\u7f3a\u5931\u6a94\u6848\u3001\u6b0a\u9650\u932f\u8aa4\u6216\u610f\u6599\u4e4b\u5916\u7684\u7db2\u8def\u9023\u7dda\u3002\u547d\u4ee4\u6703\u6301\u7e8c\u57f7\u884c\uff0c\u76f4\u5230\u6b63\u5e38\u7d50\u675f\u6216\u767c\u751f\u5d29\u6f70\u3002\u4e4b\u5f8c\uff0cstrace \u6703\u5728\u7d42\u7aef\u6a5f\u4e2d\u5217\u5370\u6700\u7d42\u7d50\u679c\u6458\u8981\u3002<\/p>\n<p>\u9019\u7a2e\u65b9\u6cd5\u6700\u9069\u5408\u7528\u65bc\u9664\u932f\u8173\u672c\u3001\u6e2c\u8a66\u65b0\u8edf\u9ad4\uff0c\u6216\u7406\u89e3\u67d0\u500b\u5de5\u5177\u7684\u5167\u90e8\u884c\u70ba\u3002\u4f60\u9084\u53ef\u4ee5\u642d\u914d\u5176\u4ed6\u9078\u9805\u5c0d\u7d50\u679c\u9032\u884c\u7be9\u9078\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u80fd\u53ea\u60f3\u8ffd\u8e64\u8207\u6a94\u6848\u76f8\u95dc\u7684\u64cd\u4f5c\uff0c\u6216\u53ea\u95dc\u6ce8\u7db2\u8def\u6d3b\u52d5\u3002\u95dc\u9375\u5728\u65bc\uff0c\u4f60\u53ef\u4ee5\u5f9e\u982d\u5230\u5c3e\u638c\u63a7\u6574\u500b\u57f7\u884c\u904e\u7a0b\uff0c\u7121\u9700\u731c\u6e2c\u7a0b\u5f0f\u6bcf\u4e00\u6b65\u505a\u4e86\u4ec0\u9ebc\u3002<\/p>\n<h3>\u9644\u52a0\u5230\u6b63\u5728\u57f7\u884c\u7684\u7a0b\u5e8f<\/h3>\n<p>\u5728\u4f3a\u670d\u5668\u74b0\u5883\u4e2d\uff0c\u4f60\u7d93\u5e38\u9700\u8981\u8a3a\u65b7\u4e00\u500b\u5df2\u7d93\u5728\u57f7\u884c\u7684\u670d\u52d9\uff0c\u800c\u4e0d\u80fd\u7c21\u55ae\u5730\u91cd\u65b0\u555f\u52d5\u5b83\u5f8c\u518d\u9032\u884c\u8ffd\u8e64\u3002\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>-p<\/code> \u9078\u9805\u9644\u52a0\u5230\u4e00\u500b\u6b63\u5728\u57f7\u884c\u7684\u7a0b\u5e8f\u3002\u8a9e\u6cd5\u662f <code>strace -p PID<\/code>\uff0c\u5176\u4e2d PID \u8868\u793a\u7a0b\u5e8f ID\u3002\u4f60\u5fc5\u9808\u5148\u77e5\u9053\u8981\u6aa2\u67e5\u7684\u7a0b\u5e8f\u865f\uff0c\u53ef\u4ee5\u900f\u904e <code>ps<\/code> \u6216 <code>pgrep<\/code> \u7b49\u547d\u4ee4\u4f86\u53d6\u5f97\u3002\u4f8b\u5982\uff0c<code>pgrep nginx<\/code> \u6703\u56de\u50b3\u6bcf\u500b nginx \u5de5\u4f5c\u7a0b\u5e8f\u7684 PID\u3002<\/p>\n<p>\u4e00\u65e6\u9644\u52a0\u6210\u529f\uff0cstrace \u5c31\u6703\u5f9e\u90a3\u4e00\u523b\u958b\u59cb\u64f7\u53d6\u8a72\u7a0b\u5e8f\u767c\u8d77\u7684\u6240\u6709\u7cfb\u7d71\u547c\u53eb\u3002\u88ab\u8ffd\u8e64\u7684\u7a0b\u5e8f\u6703\u7e7c\u7e8c\u6b63\u5e38\u57f7\u884c\uff0c\u4e0d\u6703\u4e2d\u65b7\u73fe\u6709\u5de5\u4f5c\uff0c\u4e5f\u4e0d\u6703\u9020\u6210\u505c\u6a5f\u3002\u9019\u9805\u80fd\u529b\u5c0d\u65bc\u751f\u7522\u74b0\u5883\u4f3a\u670d\u5668\u5c24\u5176\u5bf6\u8cb4\u3002\u4f60\u53ef\u4ee5\u89c0\u5bdf Web \u4f3a\u670d\u5668\u5982\u4f55\u8655\u7406\u8acb\u6c42\u3001\u8cc7\u6599\u5eab\u5982\u4f55\u57f7\u884c\u67e5\u8a62\uff0c\u6216\u61c9\u7528\u7a0b\u5f0f\u5982\u4f55\u5beb\u5165\u65e5\u8a8c\u3002\u8a72\u5de5\u5177\u4f9d\u8cf4 <code>ptrace()<\/code> \u7cfb\u7d71\u547c\u53eb\u4f86\u9644\u52a0\u5230\u53e6\u4e00\u500b\u7a0b\u5e8f\u3002\u5728 Linux \u4e2d\uff0c\u53ea\u8981\u4f60\u5177\u5099\u9069\u7576\u6b0a\u9650\uff0c\u901a\u5e38\u662f root \u4f7f\u7528\u8005\u6216\u8207\u76ee\u6a19\u7a0b\u5e8f\u76f8\u540c\u7684\u4f7f\u7528\u8005\uff0c\u5c31\u53ef\u4ee5\u57f7\u884c\u6b64\u64cd\u4f5c\u3002<\/p>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u5206\u5225\u9644\u52a0\u5230\u591a\u500b\u7279\u5b9a\u7a0b\u5e8f\u4e0a\u4e00\u4e00\u8ffd\u8e64\u3002\u5982\u679c\u67d0\u500b\u670d\u52d9\u6703\u7522\u751f\u591a\u500b worker \u7a0b\u5e8f\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5206\u5225\u9644\u52a0\u5230\u6bcf\u4e00\u500b\u7a0b\u5e8f\u3002\u6b64\u6642\uff0c<code>-f<\/code> \u9078\u9805\u5c31\u5f88\u6709\u5e6b\u52a9\uff0c\u56e0\u70ba\u5b83\u53ef\u4ee5\u81ea\u52d5\u8ffd\u8e64\u5b50\u7a0b\u5e8f\u3002\u4e0d\u904e\uff0c\u5982\u679c\u4f60\u53ea\u9700\u8981\u89c0\u5bdf\u67d0\u4e00\u500b\u7a0b\u5e8f\uff0c<code>strace -p PID<\/code> \u5c31\u80fd\u63d0\u4f9b\u8db3\u5920\u805a\u7126\u7684\u53ef\u898b\u6027\u3002\u4f60\u53ef\u4ee5\u5373\u6642\u770b\u5230\u7cfb\u7d71\u547c\u53eb\u767c\u751f\u7684\u6574\u500b\u904e\u7a0b\u3002\u89c0\u5bdf\u7d50\u675f\u5f8c\uff0c\u6309\u4e0b Ctrl+C \u5373\u53ef\u5206\u96e2\u3002\u76ee\u6a19\u7a0b\u5e8f\u6703\u7e7c\u7e8c\u57f7\u884c\uff0c\u4e0d\u53d7\u5f71\u97ff\u3002\u9019\u7a2e\u975e\u4fb5\u5165\u5f0f\u65b9\u5f0f\u8b93 strace \u6210\u70ba\u7e41\u5fd9\u4f3a\u670d\u5668\u4e0a\u7684\u5f37\u5927\u8a3a\u65b7\u5de5\u5177\u3002\u4f60\u53ef\u4ee5\u5728\u4e0d\u5f71\u97ff\u696d\u52d9\u904b\u4f5c\u7684\u524d\u63d0\u4e0b\uff0c\u6d1e\u5bdf\u5373\u6642\u884c\u70ba\u3002<\/p>\n<h2><strong>Linux \u4e2d strace \u7684\u6838\u5fc3\u9078\u9805<\/strong><\/h2>\n<h3>\u8ffd\u8e64\u5b50\u7a0b\u5e8f<\/h3>\n<p>\u8a31\u591a\u4f3a\u670d\u5668\u61c9\u7528\u4e26\u4e0d\u662f\u55ae\u7a0b\u5e8f\u57f7\u884c\u7684\u3002\u50cf Apache \u6216 Nginx \u9019\u6a23\u7684 Web \u4f3a\u670d\u5668\u6703\u5efa\u7acb\u591a\u500b worker \u7a0b\u5e8f\u4f86\u8655\u7406\u4e26\u884c\u8acb\u6c42\u3002\u8cc7\u6599\u5eab\u4e5f\u53ef\u80fd fork \u51fa\u8f14\u52a9\u7a0b\u5e8f\u4f86\u57f7\u884c\u80cc\u666f\u4efb\u52d9\u3002\u5982\u679c\u4f60\u53ea\u8ffd\u8e64\u4e3b\u7a0b\u5e8f\uff0c\u5c31\u6703\u932f\u904e\u9019\u4e9b worker \u4e2d\u767c\u751f\u7684\u5927\u91cf\u6d3b\u52d5\u3002<code>-f<\/code> \u9078\u9805\u6b63\u662f\u70ba\u4e86\u89e3\u6c7a\u9019\u500b\u554f\u984c\u800c\u8a2d\u8a08\u7684\u3002\u5b83\u6703\u544a\u8a34 strace \u8ffd\u8e64\u7531 fork\u3001clone \u6216 vfork \u5efa\u7acb\u7684\u5b50\u7a0b\u5e8f\u3002\u4e00\u65e6\u6709\u65b0\u7a0b\u5e8f\u51fa\u73fe\uff0cstrace \u5c31\u6703\u81ea\u52d5\u958b\u59cb\u5c0d\u5176\u9032\u884c\u8ffd\u8e64\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u9019\u6a23\u4f7f\u7528\u8a72\u9078\u9805\uff1a<code>strace -f -p PID<\/code>\u3002\u8a72\u5de5\u5177\u6703\u5148\u9644\u52a0\u5230\u4e3b\u7a0b\u5e8f\uff0c\u7136\u5f8c\u7e7c\u7e8c\u89c0\u5bdf\u5b83\u5efa\u7acb\u7684\u6bcf\u4e00\u500b\u5b50\u7a0b\u5e8f\u3002\u9019\u9805\u80fd\u529b\u5c0d\u65bc\u8ffd\u8e64\u6703\u884d\u751f worker \u7684\u4f3a\u670d\u5668\u7a0b\u5f0f\u81f3\u95dc\u91cd\u8981\u3002\u5982\u679c\u4e0d\u52a0 <code>-f<\/code>\uff0c\u4f60\u53ea\u80fd\u770b\u5230\u7236\u7a0b\u5e8f\u7684\u7cfb\u7d71\u547c\u53eb\uff1b\u52a0\u4e0a\u5b83\u5f8c\uff0c\u4f60\u5c31\u80fd\u7372\u5f97\u6574\u500b\u7a0b\u5e8f\u6a39\u7684\u5b8c\u6574\u8996\u5716\u3002\u8f38\u51fa\u4e2d\u6703\u70ba\u6bcf\u6b21\u7cfb\u7d71\u547c\u53eb\u6a19\u8a3b\u767c\u8d77\u8a72\u547c\u53eb\u7684 PID\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u8f15\u9b06\u5340\u5206\u4e3b\u7a0b\u5e8f\u8207\u5176\u5b50\u7a0b\u5e8f\u3002<\/p>\n<p>\u4ee5 PHP-FPM \u4f3a\u670d\u5668\u8655\u7406 Web \u8acb\u6c42\u70ba\u4f8b\uff1a\u4e3b\u7a0b\u5e8f\u63a5\u6536\u9023\u7dda\uff0c\u4e26\u5c07\u4efb\u52d9\u5206\u914d\u7d66 worker \u7a0b\u5e8f\u3002\u5982\u679c\u4e0d\u4f7f\u7528 <code>-f<\/code>\uff0c\u4f60\u770b\u5230\u7684\u53ea\u6709\u4e3b\u7a0b\u5e8f\u7684\u6d3b\u52d5\uff1b\u800c\u52a0\u5165 <code>-f<\/code> \u5f8c\uff0c\u4f60\u5c31\u80fd\u7cbe\u78ba\u770b\u5230\u6bcf\u500b worker \u662f\u5982\u4f55\u8655\u7406\u6bcf\u4e00\u500b\u8acb\u6c42\u7684\u3002\u4f60\u53ef\u4ee5\u770b\u5230\u8de8 worker \u7684\u6a94\u6848\u8b80\u53d6\u3001\u8cc7\u6599\u5eab\u67e5\u8a62\u8207\u7db2\u8def\u64cd\u4f5c\u3002\u9019\u7a2e\u53ef\u898b\u6027\u6709\u52a9\u65bc\u4f60\u8b58\u5225\u7279\u5b9a worker \u7a0b\u5e8f\u4e2d\u7684\u74f6\u9838\u6216\u932f\u8aa4\u3002<\/p>\n<h3>\u7be9\u9078\u7cfb\u7d71\u547c\u53eb<\/h3>\n<p>\u7e41\u5fd9\u7684\u4f3a\u670d\u5668\u6bcf\u79d2\u6703\u7522\u751f\u6210\u5343\u4e0a\u842c\u6b21\u7cfb\u7d71\u547c\u53eb\u3002\u5982\u679c\u5168\u90e8\u8ffd\u8e64\uff0c\u8f38\u51fa\u91cf\u6703\u6975\u5176\u9f90\u5927\uff0c\u53cd\u800c\u63a9\u84cb\u4f60\u771f\u6b63\u9700\u8981\u7684\u8cc7\u8a0a\u3002<code>-e trace=<\/code> \u9078\u9805\u53ef\u4ee5\u5c07\u8ffd\u8e64\u7bc4\u570d\u9650\u5b9a\u5728\u7279\u5b9a\u7684\u7cfb\u7d71\u547c\u53eb\u4e0a\u3002\u4f60\u53ea\u9700\u6307\u5b9a\u81ea\u5df1\u611f\u8208\u8da3\u7684\u547c\u53eb\uff0cstrace \u5c31\u6703\u5ffd\u7565\u5176\u4ed6\u5167\u5bb9\u3002\u4f8b\u5982\uff0c<code>strace -e trace=open,read,write<\/code> \u53ea\u6703\u64f7\u53d6\u6a94\u6848\u64cd\u4f5c\u8207\u8cc7\u6599\u50b3\u8f38\u76f8\u95dc\u7684\u7cfb\u7d71\u547c\u53eb\u3002\u9019\u7a2e\u805a\u7126\u5f0f\u65b9\u6cd5\u80fd\u6709\u6548\u6e1b\u5c11\u96dc\u8a0a\uff0c\u51f8\u986f\u95dc\u9375\u884c\u70ba\u3002<\/p>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u6309\u985e\u5225\u800c\u4e0d\u662f\u55ae\u500b\u547c\u53eb\u4f86\u7be9\u9078\u3002<code>%process<\/code> \u985e\u5225\u5305\u542b fork\u3001wait \u8207 exec \u7b49\u7a0b\u5e8f\u7ba1\u7406\u76f8\u95dc\u547c\u53eb\u3002\u4f7f\u7528 <code>-e trace=%process<\/code> \u53ef\u4ee5\u67e5\u770b\u4e00\u500b\u7a0b\u5f0f\u662f\u5982\u4f55\u5efa\u7acb\u8207\u7ba1\u7406\u5b50\u7a0b\u5e8f\u7684\u3002<code>%signal<\/code> \u985e\u5225\u6db5\u84cb kill \u8207 sigaction \u7b49\u8207\u8a0a\u865f\u76f8\u95dc\u7684\u547c\u53eb\uff0c\u9019\u6709\u52a9\u65bc\u4f60\u9664\u932f\u8a0a\u865f\u8655\u7406\u554f\u984c\u3002<code>%pure<\/code> \u985e\u5225\u5247\u5305\u542b\u90a3\u4e9b\u7e3d\u662f\u6210\u529f\u4e14\u4e0d\u5e36\u53c3\u6578\u7684\u7cfb\u7d71\u547c\u53eb\uff0c\u4f8b\u5982 getpid\u3002\u9019\u985e\u547c\u53eb\u901a\u5e38\u5f88\u5c11\u6210\u70ba\u554f\u984c\u6839\u6e90\uff0c\u56e0\u6b64\u7be9\u9078\u6389\u5b83\u5011\u80fd\u6e1b\u5c11\u8f38\u51fa\u5e72\u64fe\u3002<\/p>\n<p>\u5c07\u9019\u4e9b\u7be9\u9078\u5668\u8207 <code>-f<\/code> \u7d50\u5408\u4f7f\u7528\uff0c\u53ef\u4ee5\u5be6\u73fe\u975e\u5e38\u7cbe\u7d30\u7684\u63a7\u5236\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u53ea\u8ffd\u8e64\u6240\u6709\u5b50\u7a0b\u5e8f\u4e2d\u7684\u7db2\u8def\u76f8\u95dc\u547c\u53eb\u3002\u547d\u4ee4 <code>strace -f -e trace=network -p PID<\/code> \u6703\u64f7\u53d6\u6bcf\u500b worker \u7684 socket \u64cd\u4f5c\u3002\u9019\u7a2e\u5b9a\u5411\u8ffd\u8e64\u65b9\u5f0f\u975e\u5e38\u9069\u5408\u7528\u65bc\u8a3a\u65b7\u9023\u7dda\u554f\u984c\u6216\u6548\u80fd\u7570\u5e38\u3002<\/p>\n<p>\u5982\u679c\u4f60\u9700\u8981\u4fdd\u5b58\u7d50\u679c\uff0c\u53ef\u4f7f\u7528 <code>-o<\/code> \u9078\u9805\u4e26\u6307\u5b9a\u6a94\u540d\u3002\u9019\u6a23\uff0c\u8ffd\u8e64\u8f38\u51fa\u5c31\u6703\u5beb\u5165\u6a94\u6848\uff0c\u800c\u4e0d\u662f\u986f\u793a\u5728\u7d42\u7aef\u6a5f\u4e2d\u3002\u547d\u4ee4 <code>strace -o trace.log -p PID<\/code> \u6703\u5c07\u6240\u6709\u64f7\u53d6\u5230\u7684\u8cc7\u6599\u5beb\u5165 trace.log\u3002\u4f60\u53ef\u4ee5\u7a0d\u5f8c\u518d\u67e5\u770b\u9019\u500b\u6a94\u6848\uff0c\u6216\u5206\u4eab\u7d66\u540c\u4e8b\u3002\u5c07\u8f38\u51fa\u5beb\u5165\u6a94\u6848\u9084\u80fd\u907f\u514d\u8ffd\u8e64\u8cc7\u8a0a\u8207\u7d42\u7aef\u6a5f\u4e2d\u7684\u6b63\u5e38\u986f\u793a\u5167\u5bb9\u6df7\u5728\u4e00\u8d77\u3002\u5c0d\u65bc\u9577\u6642\u9593\u57f7\u884c\u7684\u8ffd\u8e64\u4efb\u52d9\uff0c\u4f60\u53ef\u4ee5\u628a\u8ffd\u8e64\u7d50\u679c\u91cd\u65b0\u5c0e\u5411\u5230\u6587\u5b57\u6a94\u4e2d\uff0c\u5728\u5206\u96e2\u5f8c\u518d\u9032\u884c\u5206\u6790\u3002\u9019\u7a2e\u65b9\u6cd5\u65e2\u80fd\u4fdd\u6301\u7d42\u7aef\u6a5f\u6574\u6f54\uff0c\u4e5f\u80fd\u4fdd\u7559\u8cc7\u6599\u4ee5\u4fbf\u6df1\u5165\u6aa2\u67e5\u3002<code>-o<\/code> \u9078\u9805\u53ef\u4ee5\u8207\u6240\u6709\u5176\u4ed6\u7be9\u9078\u5668\u642d\u914d\u4f7f\u7528\uff0c\u56e0\u6b64\u4f60\u4e5f\u53ef\u4ee5\u53ea\u4fdd\u5b58\u81ea\u5df1\u771f\u6b63\u95dc\u5fc3\u7684\u90a3\u4e9b\u7cfb\u7d71\u547c\u53eb\u3002<\/p>\n<h2><strong>\u4f7f\u7528 strace \u5206\u6790\u6548\u80fd<\/strong><\/h2>\n<h3>\u7cfb\u7d71\u547c\u53eb\u6458\u8981<\/h3>\n<p>\u4f60\u9084\u53ef\u4ee5\u85c9\u52a9 <code>-c<\/code> \u9078\u9805\uff0c\u5c07 strace \u8b8a\u6210\u4e00\u500b\u6548\u80fd\u5206\u6790\u5de5\u5177\u3002\u9019\u500b\u53c3\u6578\u4e0d\u6703\u8f38\u51fa\u9010\u884c\u8ffd\u8e64\u7d50\u679c\uff0c\u800c\u662f\u7522\u751f\u4e00\u5f35\u6458\u8981\u8868\u3002\u8868\u683c\u6703\u986f\u793a\u6bcf\u7a2e\u7cfb\u7d71\u547c\u53eb\u7684\u6b21\u6578\u3001\u932f\u8aa4\u6578\u91cf\u4ee5\u53ca\u7e3d\u8017\u6642\u3002\u9019\u6a23\u4f60\u5c31\u80fd\u5feb\u901f\u770b\u51fa\u54ea\u4e9b\u64cd\u4f5c\u4f54\u64da\u4e86\u4e3b\u8981\u958b\u92b7\uff0c\u800c\u7121\u9700\u95b1\u8b80\u6210\u5343\u4e0a\u842c\u884c\u7d30\u7bc0\u3002<\/p>\n<p>\u57f7\u884c <code>strace -c -p PID<\/code> \u5373\u53ef\u9644\u52a0\u5230\u4e00\u500b\u6b63\u5728\u57f7\u884c\u7684\u670d\u52d9\u4e26\u958b\u59cb\u8490\u96c6\u8cc7\u6599\u3002\u8b93\u8ffd\u8e64\u57f7\u884c\u5e7e\u79d2\u9418\u6216\u5e7e\u5206\u9418\u5f8c\uff0c\u6309\u4e0b Ctrl+C\uff0cstrace \u5c31\u6703\u5728\u7d42\u7aef\u6a5f\u4e2d\u5217\u5370\u6458\u8981\u8868\u3002\u8a72\u8868\u901a\u5e38\u6309\u8017\u6642\u6392\u5e8f\u3002\u4f60\u53ef\u80fd\u6703\u767c\u73fe <code>read<\/code> \u64cd\u4f5c\u4f54\u64da\u4e86 80% \u7684\u6642\u9593\uff0c\u6216\u8005\u770b\u5230 <code>poll<\/code> \u547c\u53eb\u4f54\u4e3b\u5c0e\u5730\u4f4d\uff0c\u9019\u901a\u5e38\u8868\u793a\u7a0b\u5e8f\u8655\u65bc\u9592\u7f6e\u7b49\u5f85\u72c0\u614b\u3002\u9019\u4e9b\u8cc7\u8a0a\u80fd\u5e6b\u52a9\u4f60\u628a\u6700\u4f73\u5316\u7cbe\u529b\u96c6\u4e2d\u5230\u771f\u6b63\u7684\u554f\u984c\u5340\u57df\u3002<\/p>\n<p>\u6458\u8981\u8868\u9084\u6703\u986f\u793a\u6bcf\u7a2e\u7cfb\u7d71\u547c\u53eb\u7684\u932f\u8aa4\u8a08\u6578\u3002\u5982\u679c <code>open<\/code> \u6216 <code>connect<\/code> \u7684\u932f\u8aa4\u6578\u5f88\u9ad8\uff0c\u5f80\u5f80\u8868\u793a\u5b58\u5728\u8a2d\u5b9a\u554f\u984c\u3002\u770b\u5230\u9019\u7a2e\u6a21\u5f0f\u5f8c\uff0c\u4f60\u5c31\u53ef\u4ee5\u9032\u4e00\u6b65\u8abf\u67e5\u9019\u4e9b\u5931\u6557\u547c\u53eb\u3002<code>-c<\/code> \u9078\u9805\u4e5f\u53ef\u4ee5\u8207 <code>-f<\/code> \u4e00\u8d77\u4f7f\u7528\uff0c\u5f9e\u800c\u628a\u5b50\u7a0b\u5e8f\u7d0d\u5165\u7d71\u8a08\u6458\u8981\u4e2d\u3002\u9019\u6a23\uff0c\u4f60\u5c31\u80fd\u5c0d\u6574\u500b\u7a0b\u5e8f\u6a39\u9032\u884c\u6548\u80fd\u5206\u6790\uff0c\u5f9e\u6240\u6709 worker \u7684\u89d2\u5ea6\u7372\u5f97\u5b8c\u6574\u7684\u6548\u80fd\u8f2a\u5ed3\u3002<\/p>\n<h3>\u6642\u9593\u6233\u8207\u5ef6\u9072<\/h3>\n<p>\u6709\u6642\uff0c\u4f60\u9700\u8981\u77e5\u9053\u6bcf\u4e00\u6b21\u7cfb\u7d71\u547c\u53eb\u767c\u751f\u7684\u5177\u9ad4\u6642\u9593\u3002<code>-t<\/code> \u9078\u9805\u6703\u70ba\u8f38\u51fa\u4e2d\u7684\u6bcf\u4e00\u884c\u52a0\u5165\u6642\u9593\u6233\u3002\u6bcf\u500b\u6642\u9593\u6233\u90fd\u986f\u793a\u7576\u5929\u6642\u9593\uff0c\u7cbe\u78ba\u5230\u79d2\u3002\u9019\u6a23\u4f60\u5c31\u53ef\u4ee5\u628a\u7cfb\u7d71\u547c\u53eb\u8207\u5916\u90e8\u4e8b\u4ef6\u5c0d\u61c9\u8d77\u4f86\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u628a\u4e00\u6b21\u7de9\u6162\u7684\u8cc7\u6599\u5eab\u67e5\u8a62\u8207\u67d0\u500b\u7279\u5b9a\u7684 <code>read<\/code> \u547c\u53eb\u95dc\u806f\u8d77\u4f86\u3002<code>-tt<\/code> \u9078\u9805\u5247\u6703\u9032\u4e00\u6b65\u63d0\u5347\u5230\u5fae\u79d2\u7d1a\u7cbe\u5ea6\uff0c\u6709\u52a9\u65bc\u63ed\u793a\u76f8\u95dc\u7cfb\u7d71\u547c\u53eb\u4e4b\u9593\u7684\u77ed\u66ab\u5ef6\u9072\u3002<\/p>\n<p><code>-r<\/code> \u9078\u9805\u63d0\u4f9b\u76f8\u5c0d\u6642\u9593\u6233\u3002\u6bcf\u4e00\u884c\u90fd\u6703\u986f\u793a\u8ddd\u96e2\u4e0a\u4e00\u6b21\u7cfb\u7d71\u547c\u53eb\u7d93\u904e\u4e86\u591a\u9577\u6642\u9593\u3002\u9019\u7a2e\u683c\u5f0f\u975e\u5e38\u9069\u5408\u7528\u4f86\u767c\u73fe\u64cd\u4f5c\u4e4b\u9593\u7684\u5ef6\u9072\u3002\u4f60\u53ef\u4ee5\u6e05\u695a\u770b\u5230\u67d0\u6b21 <code>write<\/code> \u547c\u53eb\u8207\u5c0d\u61c9\u7684 <code>read<\/code> \u547c\u53eb\u4e4b\u9593\u662f\u5426\u5b58\u5728\u8f03\u9577\u9593\u9694\u3002\u9019\u6a23\u7684\u9593\u9694\u53ef\u80fd\u610f\u5473\u8457\u7db2\u8def\u5ef6\u9072\uff0c\u4e5f\u53ef\u80fd\u8868\u793a\u78c1\u789f I\/O \u8b8a\u6162\u3002\u76f8\u5c0d\u6642\u9593\u6233\u6703\u8b93\u9019\u4e9b\u554f\u984c\u4e00\u76ee\u4e86\u7136\u3002<\/p>\n<p>\u4f60\u9084\u53ef\u4ee5\u628a\u6642\u9593\u6233\u8207\u7be9\u9078\u5668\u7d50\u5408\u8d77\u4f86\uff0c\u5c07\u6ce8\u610f\u529b\u96c6\u4e2d\u5230\u7279\u5b9a\u884c\u70ba\u4e0a\u3002\u4f8b\u5982\uff0c\u53ea\u8ffd\u8e64\u7db2\u8def\u76f8\u95dc\u547c\u53eb\u4e26\u52a0\u5165 <code>-tt<\/code> \u4ee5\u53d6\u5f97\u5fae\u79d2\u7d1a\u7cbe\u5ea6\u3002\u9019\u6a23\uff0c\u4f60\u5c31\u80fd\u6e96\u78ba\u770b\u5230\u9023\u7dda\u5ef6\u9072\u5177\u9ad4\u767c\u751f\u5728\u54ea\u4e00\u6b65\u3002\u4f60\u4e5f\u53ef\u4ee5\u628a\u9019\u4e9b\u8f38\u51fa\u4fdd\u5b58\u5230\u6a94\u6848\u4e2d\uff0c\u4ee5\u4fbf\u5f8c\u7e8c\u5206\u6790\u3002\u4fdd\u5b58\u5f8c\u7684\u6a94\u6848\u6703\u4fdd\u7559\u6642\u9593\u6233\uff0c\u5f9e\u800c\u5b8c\u6574\u4fdd\u7559\u6642\u5e8f\u8cc7\u8a0a\u3002\u9019\u7a2e\u505a\u6cd5\u4e5f\u6709\u52a9\u65bc\u5718\u968a\u8a18\u9304\u6548\u80fd\u554f\u984c\uff0c\u4e26\u5728\u4fee\u6539\u5f8c\u6bd4\u8f03\u4e0d\u540c\u6642\u9593\u9ede\u7684\u8ffd\u8e64\u7d50\u679c\uff0c\u4ee5\u8a55\u4f30\u6700\u4f73\u5316\u6548\u679c\u3002<\/p>\n<h2><strong>\u5728\u7e41\u5fd9\u4f3a\u670d\u5668\u4e0a\u7ba1\u7406\u5927\u91cf\u8f38\u51fa<\/strong><\/h2>\n<h3>\u58d3\u7e2e\u8ffd\u8e64\u8f38\u51fa<\/h3>\n<p>\u9ad8\u6d41\u91cf\u4f3a\u670d\u5668\u5728\u8ffd\u8e64\u671f\u9593\u6703\u7522\u751f\u6d77\u91cf\u8cc7\u6599\u3002\u6bcf\u4e00\u6b21\u6a94\u6848\u8b80\u53d6\u3001\u7db2\u8def\u5c01\u5305\u8655\u7406\u4ee5\u53ca\u8a18\u61b6\u9ad4\u64cd\u4f5c\uff0c\u90fd\u6703\u7522\u751f\u4e00\u884c\u6587\u5b57\u3002\u7576\u4f60\u8ffd\u8e64\u7e41\u5fd9\u7684 Web \u4f3a\u670d\u5668\u6216\u8cc7\u6599\u5eab\u6642\uff0c\u78c1\u789f\u7a7a\u9593\u53ef\u80fd\u5f88\u5feb\u5c31\u88ab\u8017\u76e1\u3002<code>-C<\/code> \u9078\u9805\u53ef\u4ee5\u89e3\u6c7a\u9019\u500b\u554f\u984c\uff0c\u5b83\u80fd\u5920\u5728\u5beb\u51fa\u8ffd\u8e64\u7d50\u679c\u6642\u5373\u6642\u9032\u884c\u58d3\u7e2e\u3002\u9019\u500b\u53c3\u6578\u901a\u5e38\u8207 <code>-o<\/code> \u642d\u914d\u4f7f\u7528\uff0c\u628a\u58d3\u7e2e\u5f8c\u7684\u8cc7\u6599\u76f4\u63a5\u5beb\u5165\u6a94\u6848\u3002\u6700\u7d42\u4f60\u5f97\u5230\u7684\u662f\u4e00\u500b <code>.gz<\/code> \u6a94\u6848\uff0c\u800c\u4e0d\u662f\u4e00\u822c\u6587\u5b57\u6a94\u3002\u9019\u7a2e\u65b9\u5f0f\u80fd\u5920\u986f\u8457\u6e1b\u5c11\u5132\u5b58\u7a7a\u9593\u5360\u7528\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u8ffd\u8e64\u4e00\u500b\u6bcf\u79d2\u8655\u7406\u6578\u767e\u500b\u8acb\u6c42\u7684\u7a0b\u5e8f\uff0c\u4e0d\u58d3\u7e2e\u7684\u8a71\uff0c\u5e7e\u5206\u9418\u5167\u5c31\u53ef\u80fd\u7522\u751f\u6578 GB \u7684\u8cc7\u6599\uff1b\u800c\u555f\u7528 <code>-C<\/code> \u5f8c\uff0c\u8f38\u51fa\u9ad4\u7a4d\u6703\u660e\u986f\u7e2e\u5c0f\u3002\u58d3\u7e2e\u662f\u5728 strace \u64f7\u53d6\u6bcf\u4e00\u500b\u7cfb\u7d71\u547c\u53eb\u6642\u5373\u6642\u5b8c\u6210\u7684\uff0c\u56e0\u6b64\u4f60\u7121\u9700\u5728\u4e8b\u5f8c\u518d\u624b\u52d5\u58d3\u7e2e\u6a94\u6848\u3002\u5c0d\u65bc\u751f\u7522\u4f3a\u670d\u5668\u4e0a\u78c1\u789f\u7a7a\u9593\u6709\u9650\u7684\u5834\u666f\uff0c\u9019\u9805\u529f\u80fd\u5c24\u5176\u5be6\u7528\u3002\u4f60\u53ef\u4ee5\u9032\u884c\u66f4\u9577\u6642\u9593\u7684\u8ffd\u8e64\uff0c\u800c\u4e0d\u5fc5\u904e\u5ea6\u64d4\u5fc3\u6a94\u6848\u7cfb\u7d71\u88ab\u5beb\u6eff\u3002<\/p>\n<h3>\u8f2a\u66ff\u9577\u6642\u9593\u57f7\u884c\u7684\u8ffd\u8e64\u6a94\u6848<\/h3>\n<p>\u9577\u6642\u9593\u57f7\u884c\u7684\u8ffd\u8e64\u4efb\u52d9\u9084\u6703\u5e36\u4f86\u53e6\u4e00\u500b\u6311\u6230\u3002\u4f60\u53ef\u80fd\u9700\u8981\u9023\u7e8c\u76e3\u63a7\u67d0\u9805\u670d\u52d9\u6578\u5c0f\u6642\uff0c\u624d\u80fd\u6355\u6349\u5230\u4e00\u500b\u5076\u767c\u6027\u554f\u984c\u3002\u82e5\u53ea\u5beb\u5165\u55ae\u4e00\u8f38\u51fa\u6a94\u6848\uff0c\u5b83\u6703\u6301\u7e8c\u589e\u5927\uff0c\u9010\u6f38\u8b8a\u5f97\u96e3\u4ee5\u7ba1\u7406\u3002\u4f60\u53ef\u4ee5\u5c07 <code>-o<\/code> \u8207 <code>logrotate<\/code> \u6216 <code>split<\/code> \u7b49\u5916\u90e8\u5de5\u5177\u642d\u914d\u4f7f\u7528\uff0c\u4ee5\u8655\u7406\u9019\u7a2e\u6301\u7e8c\u6210\u9577\u7684\u6a94\u6848\u3002<code>logrotate<\/code> \u5de5\u5177\u53ef\u4ee5\u4f9d\u7167\u6a94\u6848\u5927\u5c0f\u6216\u6642\u9593\u9593\u9694\u81ea\u52d5\u8f2a\u66ff\u65e5\u8a8c\u6a94\u3002\u4f60\u53ef\u4ee5\u5c07\u5176\u8a2d\u5b9a\u70ba\u5728\u76ee\u524d\u8ffd\u8e64\u6a94\u6848\u9054\u5230\u67d0\u500b\u689d\u4ef6\u5f8c\u81ea\u52d5\u91cd\u65b0\u547d\u540d\uff0c\u4e26\u958b\u59cb\u5beb\u5165\u65b0\u6a94\u6848\u3002\u9019\u6a23\u65e2\u80fd\u8b93\u55ae\u4e00\u6a94\u6848\u7dad\u6301\u5728\u53ef\u7ba1\u7406\u7bc4\u570d\u5167\uff0c\u4e5f\u80fd\u4fdd\u7559\u6b77\u53f2\u8cc7\u6599\u3002<\/p>\n<p><code>-ff<\/code> \u9078\u9805\u5247\u9032\u4e00\u6b65\u589e\u5f37\u4e86\u63a7\u5236\u80fd\u529b\u3002\u5c07\u5b83\u8207 <code>-o<\/code> \u7d44\u5408\u4f7f\u7528\u6642\uff0cstrace \u6703\u70ba\u6bcf\u500b\u5b50\u7a0b\u5e8f\u5206\u5225\u5efa\u7acb\u4e00\u500b\u8f38\u51fa\u6a94\u6848\u3002\u4e5f\u5c31\u662f\u8aaa\uff0c\u6bcf\u500b worker \u7a0b\u5e8f\u90fd\u6703\u5beb\u5165\u81ea\u5df1\u7684\u6a94\u6848\u3002\u4f60\u53ef\u4ee5\u5206\u5225\u5c0d\u9019\u4e9b\u6a94\u6848\u9032\u884c\u8f2a\u66ff\u7ba1\u7406\u3002\u9019\u7a2e\u65b9\u5f0f\u66f4\u5bb9\u6613\u5e6b\u52a9\u4f60\u9694\u96e2\u7279\u5b9a worker \u4e2d\u7684\u554f\u984c\u3002\u6bd4\u5982\uff0c\u4f60\u53ef\u80fd\u6703\u767c\u73fe\u67d0\u4e00\u500b worker \u6301\u7e8c\u5831\u932f\uff0c\u800c\u5176\u4ed6 worker \u90fd\u904b\u4f5c\u6b63\u5e38\u3002\u5206\u96e2\u7684\u6a94\u6848\u6703\u8b93\u9019\u7a2e\u6a21\u5f0f\u66f4\u52a0\u6e05\u6670\u3002<\/p>\n<p>\u4f60\u9084\u61c9\u7262\u8a18\uff0c\u8ffd\u8e64\u672c\u8eab\u6703\u7d66\u7cfb\u7d71\u5e36\u4f86\u984d\u5916\u958b\u92b7\u3002\u6bcf\u4e00\u500b\u88ab\u64f7\u53d6\u7684\u7cfb\u7d71\u547c\u53eb\u90fd\u9700\u8981\u984d\u5916\u8655\u7406\u6642\u9593\u3002\u5728\u7e41\u5fd9\u4f3a\u670d\u5668\u4e0a\uff0c\u9019\u7a2e\u958b\u92b7\u53ef\u80fd\u6703\u660e\u986f\u62d6\u6162\u88ab\u8ffd\u8e64\u7a0b\u5e8f\u3002\u56e0\u6b64\uff0c\u61c9\u8a72\u4f7f\u7528 <code>-e trace=<\/code> \u7be9\u9078\u5668\u4f86\u6e1b\u5c11\u64f7\u53d6\u7684\u8cc7\u6599\u91cf\uff0c\u53ea\u95dc\u6ce8\u4f60\u771f\u6b63\u9700\u8981\u7684\u7cfb\u7d71\u547c\u53eb\u3002\u9019\u6a23\u505a\u65e2\u80fd\u964d\u4f4e\u6548\u80fd\u5f71\u97ff\uff0c\u4e5f\u80fd\u6e1b\u5c11\u8f38\u51fa\u9ad4\u7a4d\uff0c\u8b93\u4f60\u7684\u4f3a\u670d\u5668\u5728\u8490\u96c6\u8a3a\u65b7\u8cc7\u8a0a\u7684\u540c\u6642\u76e1\u53ef\u80fd\u4fdd\u6301\u56de\u61c9\u80fd\u529b\u3002<\/p>\n<div class=\"qc-divider-wrapper\">\n<div class=\"qc-divider\" style=\"border-top-style: solid; width: 100%; border-top-color: #d1d1d1;\"><\/div>\n<\/div>\n<p>\u73fe\u5728\u4f60\u5df2\u7d93\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 strace \u5728 Linux \u4f3a\u670d\u5668\u4e0a\u8ffd\u8e64\u7cfb\u7d71\u547c\u53eb\uff1a\u5f9e\u8ffd\u8e64\u7c21\u55ae\u547d\u4ee4\uff0c\u5230\u6df1\u5165\u9032\u884c\u6548\u80fd\u5206\u6790\u3002\u9019\u500b Linux \u5de5\u5177\u80fd\u5920\u64f7\u53d6\u8a0a\u865f\u4ee5\u53ca\u7a0b\u5e8f\u767c\u51fa\u7684\u6bcf\u4e00\u500b\u6838\u5fc3\u8acb\u6c42\u3002\u50cf <code>-f<\/code>\u3001<code>-e trace=<\/code> \u8207 <code>-c<\/code> \u9019\u6a23\u7684\u9078\u9805\uff0c\u53ef\u4ee5\u8b93\u4f60\u7684\u8ffd\u8e64\u8f38\u51fa\u66f4\u52a0\u805a\u7126\uff0c\u4e5f\u80fd\u907f\u514d\u6d77\u91cf\u539f\u59cb\u8f38\u51fa\u6df9\u6c92\u4f60\u771f\u6b63\u9700\u8981\u7684\u90a3\u500b\u95dc\u9375\u7d30\u7bc0\u3002<\/p>\n<blockquote><p>\u5efa\u8b70\u5148\u5728\u6e2c\u8a66\u6a5f\u5668\u4e0a\u7df4\u7fd2\u3002\u5728\u751f\u7522\u74b0\u5883\u4e2d\uff0c\u8acb\u8a18\u4f4f strace \u6703\u62d6\u6162\u76ee\u6a19\u7a0b\u5e8f\uff0c\u56e0\u6b64\u61c9\u76e1\u91cf\u4f7f\u7528\u7be9\u9078\u5668\u7e2e\u5c0f\u7bc4\u570d\uff0c\u4e26\u5728\u89c0\u5bdf\u5b8c\u6210\u5f8c\u53ca\u6642\u5206\u96e2\u3002<\/p><\/blockquote>\n<p>\u53ea\u6709\u5728\u78ba\u6709\u5fc5\u8981\u6642\uff0c\u624d\u9644\u52a0\u5230\u4e00\u500b\u5df2\u7d93\u5728\u57f7\u884c\u7684\u7a0b\u5e8f\u4e0a\u3002\u53ea\u8981\u4f7f\u7528\u5f97\u7576\uff0c\u9019\u500b Linux \u5de5\u5177\u5c31\u6703\u6210\u70ba\u4f60\u6700\u53ef\u9760\u7684\u8a3a\u65b7\u5229\u5668\u4e4b\u4e00\u3002<\/p>\n<h2><strong>\u5e38\u898b\u554f\u984c<\/strong><\/h2>\n<h3>strace \u5728 Linux \u4f3a\u670d\u5668\u4e0a\u7a76\u7adf\u80fd\u505a\u4ec0\u9ebc\uff1f<\/h3>\n<p>Strace \u6703\u6514\u622a\u7a0b\u5f0f\u5411 Linux \u6838\u5fc3\u767c\u8d77\u7684\u6bcf\u4e00\u6b21\u7cfb\u7d71\u547c\u53eb\u3002\u5b83\u80fd\u5373\u6642\u5c55\u793a\u6a94\u6848\u958b\u555f\u3001\u7db2\u8def\u8b80\u53d6\u8207\u8a18\u61b6\u9ad4\u64cd\u4f5c\u7b49\u884c\u70ba\u3002\u9019\u7a2e\u53ef\u898b\u6027\u80fd\u5e6b\u52a9\u4f60\u8a3a\u65b7\u932f\u8aa4\u3001\u627e\u51fa\u74f6\u9838\uff0c\u4e26\u5728\u7121\u9700\u731c\u6e2c\u7684\u524d\u63d0\u4e0b\u7406\u89e3\u61c9\u7528\u7a0b\u5f0f\u7684\u57f7\u884c\u65b9\u5f0f\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 strace \u8ffd\u8e64\u7cfb\u7d71\u547c\u53eb\uff0c\u7528\u65bc\u9664\u932f\u6216\u6548\u80fd\u5206\u6790\u3002<\/p>\n<h3>\u5982\u4f55\u628a strace \u9644\u52a0\u5230\u4e00\u500b\u6b63\u5728\u57f7\u884c\u7684\u670d\u52d9\u4e0a\uff1f<\/h3>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528\u5e36\u6709\u7a0b\u5e8f ID \u7684 <code>-p<\/code> \u9078\u9805\u3002\u9996\u5148\uff0c\u4f7f\u7528 ps \u6216 pgrep \u627e\u5230\u76ee\u6a19\u7a0b\u5e8f\u7684 PID\u3002\u7136\u5f8c\u57f7\u884c <code>strace -p PID<\/code>\u3002\u8a72\u5de5\u5177\u6703\u7acb\u523b\u9644\u52a0\u5230\u8a72\u7a0b\u5e8f\u4e26\u958b\u59cb\u64f7\u53d6\u5b83\u7684\u7cfb\u7d71\u547c\u53eb\u3002\u6309\u4e0b Ctrl+C \u5373\u53ef\u5206\u96e2\u3002\u9019\u7a2e\u65b9\u6cd5\u9069\u7528\u65bc\u4efb\u4f55 Linux \u767c\u884c\u7248\u3002<\/p>\n<h3>strace \u6703\u5f71\u97ff\u4f3a\u670d\u5668\u6548\u80fd\u55ce\uff1f<\/h3>\n<p>\u6703\u3002\u8ffd\u8e64\u6703\u5e36\u4f86\u984d\u5916\u958b\u92b7\u3002\u6bcf\u4e00\u500b\u88ab\u64f7\u53d6\u7684\u7cfb\u7d71\u547c\u53eb\u90fd\u9700\u8981\u984d\u5916\u8655\u7406\u6642\u9593\u3002\u5728\u7e41\u5fd9\u4f3a\u670d\u5668\u4e0a\uff0c\u9019\u7a2e\u958b\u92b7\u53ef\u80fd\u6703\u660e\u986f\u62d6\u6162\u88ab\u8ffd\u8e64\u7a0b\u5e8f\u3002\u53ef\u4ee5\u4f7f\u7528 <code>-e trace=<\/code> \u4e4b\u985e\u7684\u7be9\u9078\u5668\u4f86\u9650\u5236\u64f7\u53d6\u7bc4\u570d\uff0c\u5f9e\u800c\u540c\u6642\u964d\u4f4e\u6548\u80fd\u5f71\u97ff\u8207\u8f38\u51fa\u9ad4\u7a4d\u3002Linux \u7cfb\u7d71\u7ba1\u7406\u54e1\u901a\u5e38\u90fd\u61c9\u76e1\u91cf\u9032\u884c\u7cbe\u7d30\u7be9\u9078\u3002<\/p>\n<h3>\u8ffd\u8e64\u7a0b\u5e8f\u9700\u8981\u4ec0\u9ebc\u6b0a\u9650\uff1f<\/h3>\n<p>\u4f60\u9700\u8981 root \u6b0a\u9650\uff0c\u6216\u4f7f\u7528\u8207\u76ee\u6a19\u7a0b\u5e8f\u76f8\u540c\u7684\u4f7f\u7528\u8005\u5e33\u865f\u3002\u51fa\u65bc\u5b89\u5168\u539f\u56e0\uff0cLinux \u6703\u9650\u5236\u5c0d <code>ptrace()<\/code> \u7684\u5b58\u53d6\u3002\u5982\u679c\u6b0a\u9650\u4e0d\u8db3\uff0cstrace \u6703\u56de\u50b3\u932f\u8aa4\u3002\u8ffd\u8e64\u5176\u4ed6\u4f7f\u7528\u8005\u64c1\u6709\u7684\u670d\u52d9\u6642\uff0c\u8acb\u4ee5 root \u8eab\u5206\u57f7\u884c strace\uff0c\u6216\u4f7f\u7528 sudo\u3002<\/p>\n<h3>\u6211\u53ef\u4ee5\u540c\u6642\u8ffd\u8e64\u591a\u500b\u7a0b\u5e8f\u55ce\uff1f<\/h3>\n<p>\u53ef\u4ee5\uff0c\u4f7f\u7528 <code>-f<\/code> \u9078\u9805\u5373\u53ef\u8ffd\u8e64\u5b50\u7a0b\u5e8f\u3002\u9019\u6a23\u53ef\u4ee5\u540c\u6642\u64f7\u53d6\u4e3b\u7a0b\u5e8f\u53ca\u5176\u6240\u6709 worker \u7684\u7cfb\u7d71\u547c\u53eb\u3002\u8f38\u51fa\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u6703\u986f\u793a\u767c\u8d77\u8a72\u547c\u53eb\u7684\u7a0b\u5e8f PID\u3002\u9019\u7a2e\u65b9\u6cd5\u975e\u5e38\u9069\u5408\u90a3\u4e9b\u6703\u5efa\u7acb\u591a\u500b worker \u7684\u4f3a\u670d\u5668\u7a0b\u5f0f\u3002Linux \u4f3a\u670d\u5668\u901a\u5e38\u6703\u540c\u6642\u57f7\u884c\u8a31\u591a worker \u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Strace \u662f\u4e00\u6b3e Linux \u547d\u4ee4\u5217\u5de5\u5177\uff0c\u5b83\u85c9\u52a9 ptrace() \u7cfb\u7d71\u547c\u53eb\u5373\u6642\u6514\u622a\u7cfb\u7d71\u547c\u53eb\u8207\u8a0a\u865f\uff0c\u80fd\u5920\u7cbe [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/how-to-use-strace-to-trace-system-calls-of-a-process\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":2,"featured_media":35220,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[61],"tags":[13799,13800,13801,13802,5348],"class_list":["post-35223","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hong-kong-dedicated-server-tc","tag-strace","tag-linux-system-calls","tag-process-tracing","tag-linux-debugging","tag-server-troubleshooting-tc"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u5982\u4f55\u4f7f\u7528 strace \u8ffd\u8e64\u7a0b\u5e8f\u7684\u7cfb\u7d71\u547c\u53eb<\/title>\n<meta name=\"description\" content=\"\u4f7f\u7528 strace \u5728 Linux \u4f3a\u670d\u5668\u4e0a\u8ffd\u8e64\u7cfb\u7d71\u547c\u53eb\u3002\u53ef\u9644\u52a0\u5230\u6b63\u5728\u57f7\u884c\u7684\u7a0b\u5e8f\uff0c\u7be9\u9078\u8f38\u51fa\uff0c\u4e26\u900f\u904e -p\u3001-f \u8207 -c \u7b49\u9078\u9805\u5206\u6790\u6548\u80fd\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/35223\" \/>\n<meta property=\"og:locale\" content=\"zh_TW\" \/>\n<meta property=\"og:type\" content=\"company\" \/>\n<meta property=\"og:title\" content=\"\u5982\u4f55\u4f7f\u7528 strace \u8ffd\u8e64\u7a0b\u5e8f\u7684\u7cfb\u7d71\u547c\u53eb\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/35223\" \/>\n<meta property=\"og:site_name\" content=\"\u65b0\u5929\u57df\u4e92\u806f\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-18T00:00:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.simcentric.com\/wp-content\/uploads\/2026\/10\/sim-blog-2026-10-18-blogA.png\" \/>\n\t<meta property=\"og:image:width\" content=\"604\" \/>\n\t<meta property=\"og:image:height\" content=\"406\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5982\u4f55\u4f7f\u7528 strace \u8ffd\u8e64\u7a0b\u5e8f\u7684\u7cfb\u7d71\u547c\u53eb","description":"\u4f7f\u7528 strace \u5728 Linux \u4f3a\u670d\u5668\u4e0a\u8ffd\u8e64\u7cfb\u7d71\u547c\u53eb\u3002\u53ef\u9644\u52a0\u5230\u6b63\u5728\u57f7\u884c\u7684\u7a0b\u5e8f\uff0c\u7be9\u9078\u8f38\u51fa\uff0c\u4e26\u900f\u904e -p\u3001-f \u8207 -c \u7b49\u9078\u9805\u5206\u6790\u6548\u80fd\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/35223","og_locale":"zh_TW","og_type":"company","og_title":"\u5982\u4f55\u4f7f\u7528 strace \u8ffd\u8e64\u7a0b\u5e8f\u7684\u7cfb\u7d71\u547c\u53eb","og_url":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/35223","og_site_name":"\u65b0\u5929\u57df\u4e92\u806f","article_published_time":"2026-10-18T00:00:33+00:00","og_image":[{"width":604,"height":406,"url":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2026\/10\/sim-blog-2026-10-18-blogA.png","type":"image\/png"}],"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/#article","isPartOf":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/"},"author":{"name":"Debbie Ng","@id":"https:\/\/simcentric.com\/tc\/#\/schema\/person\/0bfc8768eb7caacbfab4a0855d805626"},"headline":"\u5982\u4f55\u4f7f\u7528 strace \u8ffd\u8e64\u7a0b\u5e8f\u7684\u7cfb\u7d71\u547c\u53eb","datePublished":"2026-10-18T00:00:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/"},"wordCount":103,"publisher":{"@id":"https:\/\/simcentric.com\/tc\/#organization"},"image":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/#primaryimage"},"thumbnailUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2026\/10\/sim-blog-2026-10-18-blogA.png","keywords":["strace","Linux\u7cfb\u7d71\u547c\u53eb","\u7a0b\u5e8f\u8ffd\u8e64","Linux\u9664\u932f","\u4f3a\u670d\u5668\u6545\u969c\u6392\u67e5"],"articleSection":["\u9999\u6e2f\u4f3a\u670d\u5668"],"inLanguage":"zh-HK"},{"@type":"WebPage","@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/","url":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/","name":"\u5982\u4f55\u4f7f\u7528 strace \u8ffd\u8e64\u7a0b\u5e8f\u7684\u7cfb\u7d71\u547c\u53eb","isPartOf":{"@id":"https:\/\/simcentric.com\/tc\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/#primaryimage"},"image":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/#primaryimage"},"thumbnailUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2026\/10\/sim-blog-2026-10-18-blogA.png","datePublished":"2026-10-18T00:00:33+00:00","description":"\u4f7f\u7528 strace \u5728 Linux \u4f3a\u670d\u5668\u4e0a\u8ffd\u8e64\u7cfb\u7d71\u547c\u53eb\u3002\u53ef\u9644\u52a0\u5230\u6b63\u5728\u57f7\u884c\u7684\u7a0b\u5e8f\uff0c\u7be9\u9078\u8f38\u51fa\uff0c\u4e26\u900f\u904e -p\u3001-f \u8207 -c \u7b49\u9078\u9805\u5206\u6790\u6548\u80fd\u3002","breadcrumb":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/#breadcrumb"},"inLanguage":"zh-HK","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/"]}]},{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/#primaryimage","url":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2026\/10\/sim-blog-2026-10-18-blogA.png","contentUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2026\/10\/sim-blog-2026-10-18-blogA.png","width":604,"height":406,"caption":"strace \u5728 Linux \u4e0a\u8ffd\u8e64\u7a0b\u5e8f\u7cfb\u7d71\u547c\u53eb"},{"@type":"BreadcrumbList","@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/how-to-use-strace-to-trace-system-calls-of-a-process\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.simcentric.com\/tc\/"},{"@type":"ListItem","position":2,"name":"\u5982\u4f55\u4f7f\u7528 strace \u8ffd\u8e64\u7a0b\u5e8f\u7684\u7cfb\u7d71\u547c\u53eb"}]},{"@type":"WebSite","@id":"https:\/\/simcentric.com\/tc\/#website","url":"https:\/\/simcentric.com\/tc\/","name":"Simcentric Solutions","description":"","publisher":{"@id":"https:\/\/simcentric.com\/tc\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/simcentric.com\/tc\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-HK"},{"@type":"Organization","@id":"https:\/\/simcentric.com\/tc\/#organization","name":"Simcentric Solutions","url":"https:\/\/simcentric.com\/tc\/","logo":{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/simcentric.com\/tc\/#\/schema\/logo\/image\/","url":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2023\/06\/sim-logo-2023.png","contentUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2023\/06\/sim-logo-2023.png","width":800,"height":222,"caption":"Simcentric Solutions"},"image":{"@id":"https:\/\/simcentric.com\/tc\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/simcentric.com\/tc\/#\/schema\/person\/0bfc8768eb7caacbfab4a0855d805626","name":"Debbie Ng","image":{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/secure.gravatar.com\/avatar\/9f3420f60d27329ed6e921ddaae5206353d0a7414d1abb6f1f0b32b4fd849965?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9f3420f60d27329ed6e921ddaae5206353d0a7414d1abb6f1f0b32b4fd849965?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9f3420f60d27329ed6e921ddaae5206353d0a7414d1abb6f1f0b32b4fd849965?s=96&d=mm&r=g","caption":"Debbie Ng"}}]}},"_links":{"self":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/35223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/comments?post=35223"}],"version-history":[{"count":1,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/35223\/revisions"}],"predecessor-version":[{"id":35225,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/35223\/revisions\/35225"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/media\/35220"}],"wp:attachment":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/media?parent=35223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/categories?post=35223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/tags?post=35223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}