{"id":3241,"date":"2019-06-25T12:58:47","date_gmt":"2019-06-25T04:58:47","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=3241"},"modified":"2019-06-25T20:02:54","modified_gmt":"2019-06-25T12:02:54","slug":"strace","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/strace","title":{"rendered":"strace\u547d\u4ee4 – \u8ddf\u8e2a\u7cfb\u7edf\u8c03\u7528"},"content":{"rendered":"\n

strace\u547d\u4ee4\u662f\u4e00\u4e2a\u96c6\u8bca\u65ad\u3001\u8c03\u8bd5\u3001\u7edf\u8ba1\u4e0e\u4e00\u4f53\u7684\u5de5\u5177\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528strace\u5bf9\u5e94\u7528\u7684\u7cfb\u7edf\u8c03\u7528\u548c\u4fe1\u53f7\u4f20\u9012\u7684\u8ddf\u8e2a\u7ed3\u679c\u6765\u5bf9\u5e94\u7528\u8fdb\u884c\u5206\u6790\uff0c\u4ee5\u8fbe\u5230\u89e3\u51b3\u95ee\u9898\u6216\u8005\u662f\u4e86\u89e3\u5e94\u7528\u5de5\u4f5c\u8fc7\u7a0b\u7684\u76ee\u7684\u3002<\/p>\n\n\n\n

strace\u5e38\u7528\u6765\u8ddf\u8e2a\u8fdb\u7a0b\u6267\u884c\u65f6\u7684\u7cfb\u7edf\u8c03\u7528\u548c\u6240\u63a5\u6536\u7684\u4fe1\u53f7\u3002 \u5728Linux\u4e16\u754c\uff0c\u8fdb\u7a0b\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u786c\u4ef6\u8bbe\u5907\uff0c\u5f53\u8fdb\u7a0b\u9700\u8981\u8bbf\u95ee\u786c\u4ef6\u8bbe\u5907(\u6bd4\u5982\u8bfb\u53d6\u78c1\u76d8\u6587\u4ef6\uff0c\u63a5\u6536\u7f51\u7edc\u6570\u636e\u7b49\u7b49)\u65f6\uff0c\u5fc5\u987b\u7531\u7528\u6237\u6001\u6a21\u5f0f\u5207\u6362\u81f3\u5185\u6838\u6001\u6a21\u5f0f\uff0c\u901a \u8fc7\u7cfb\u7edf\u8c03\u7528\u8bbf\u95ee\u786c\u4ef6\u8bbe\u5907\u3002strace\u53ef\u4ee5\u8ddf\u8e2a\u5230\u4e00\u4e2a\u8fdb\u7a0b\u4ea7\u751f\u7684\u7cfb\u7edf\u8c03\u7528,\u5305\u62ec\u53c2\u6570\uff0c\u8fd4\u56de\u503c\uff0c\u6267\u884c\u6d88\u8017\u7684\u65f6\u95f4\u3002<\/p>\n\n\n\n

\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong>strace [\u53c2\u6570]<\/p>\n\n\n\n

\u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n
-c<\/td>\u7edf\u8ba1\u6bcf\u4e00\u7cfb\u7edf\u8c03\u7528\u7684\u6240\u6267\u884c\u7684\u65f6\u95f4,\u6b21\u6570\u548c\u51fa\u9519\u7684\u6b21\u6570\u7b49<\/td><\/tr>
-d <\/td>\u8f93\u51fastrace\u5173\u4e8e\u6807\u51c6\u9519\u8bef\u7684\u8c03\u8bd5\u4fe1\u606f<\/td><\/tr>
-f<\/td>\u8ddf\u8e2a\u7531fork\u8c03\u7528\u6240\u4ea7\u751f\u7684\u5b50\u8fdb\u7a0b<\/td><\/tr>
-F<\/td>\u5c1d\u8bd5\u8ddf\u8e2avfork\u8c03\u7528.\u5728-f\u65f6,vfork\u4e0d\u88ab\u8ddf\u8e2a<\/td><\/tr>
-a <\/td>\u8bbe\u7f6e\u8fd4\u56de\u503c\u7684\u8f93\u51fa\u4f4d\u7f6e.\u9ed8\u8ba4 \u4e3a40<\/td><\/tr>
-r<\/td>\u6253\u5370\u51fa\u76f8\u5bf9\u65f6\u95f4\u5173\u4e8e\u6bcf\u4e00\u4e2a\u7cfb\u7edf\u8c03\u7528<\/td><\/tr>
-t<\/td>\u5728\u8f93\u51fa\u4e2d\u7684\u6bcf\u4e00\u884c\u524d\u52a0\u4e0a\u65f6\u95f4\u4fe1\u606f<\/td><\/tr><\/tbody><\/table>\n\n\n\n

\u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n

\u901a\u7528\u7684\u5b8c\u6574\u7528\u6cd5\uff0c\u8ddf\u8e2a28979\u8fdb\u7a0b\u7684\u6240\u6709\u7cfb\u7edf\u8c03\u7528\uff08-e trace=all\uff09\uff0c\u5e76\u7edf\u8ba1\u7cfb\u7edf\u8c03\u7528\u7684\u82b1\u8d39\u65f6\u95f4\uff0c\u4ee5\u53ca\u5f00\u59cb\u65f6\u95f4\uff08\u5e76\u4ee5\u53ef\u89c6\u5316\u7684\u65f6\u5206\u79d2\u683c\u5f0f\u663e\u793a\uff09\uff0c\u6700\u540e\u5c06\u8bb0\u5f55\u7ed3\u679c\u5b58\u5728output.txt\u6587\u4ef6\u91cc\u9762\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# strace -o output.txt -T -tt -e trace=all -p 28979<\/pre>\n\n\n\n

\u540c\u65f6\u8ddf\u8e2afork\u548cvfork\u51fa\u6765\u7684\u8fdb\u7a0b\uff0c\u628a\u6240\u6709strace\u8f93\u51fa\u5199\u5230~\/dcop-strace.txt\u91cc\u9762, \u542f\u52a8\u8c03\u8bd5dcopserver\uff1a <\/p>\n\n\n\n

[root@linuxcool ~]# strace -f -F -o ~\/dcop-strace.txt dcopserver<\/pre>\n\n\n\n

\u8bbe\u7f6e\u8fd4\u56de\u503c\u7684\u8f93\u51fa\u4f4d\u7f6e.\u9ed8\u8ba4\u4e3a40\uff1a <\/p>\n\n\n\n

[root@linuxcool ~]# strace -a column<\/pre>\n\n\n\n

\u8ddf\u8e2a whoami\u65f6\u7684\u8f93\u51fa\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# strace -o whoami-strace.txt whoami<\/pre>\n\n\n\n

\u9650\u5236strace\u53ea\u8ddf\u8e2a\u7279\u5b9a\u7684\u7cfb\u7edf\u8c03\u7528\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# strace -f -o configure-strace.txt -e execve .\/configure<\/pre>\n","protected":false},"excerpt":{"rendered":"

strace\u547d\u4ee4\u662f\u4e00\u4e2a\u96c6\u8bca\u65ad\u3001\u8c03\u8bd5\u3001\u7edf\u8ba1\u4e0e\u4e00\u4f53\u7684\u5de5\u5177\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528strace\u5bf9\u5e94\u7528\u7684\u7cfb\u7edf\u8c03\u7528\u548c\u4fe1\u53f7\u4f20\u9012\u7684\u8ddf\u8e2a […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/3241"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=3241"}],"version-history":[{"count":11,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/3241\/revisions"}],"predecessor-version":[{"id":3563,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/3241\/revisions\/3563"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=3241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=3241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=3241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}