{"id":4553,"date":"2019-08-16T23:34:01","date_gmt":"2019-08-16T15:34:01","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=4553"},"modified":"2019-08-24T01:04:19","modified_gmt":"2019-08-23T17:04:19","slug":"trap","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/trap","title":{"rendered":"trap\u547d\u4ee4 – \u6307\u5b9a\u91c7\u53d6\u7684\u52a8\u4f5c"},"content":{"rendered":"\n

trap\u547d\u4ee4\u7528\u4e8e\u6307\u5b9a\u5728\u63a5\u6536\u5230\u4fe1\u53f7\u540e\u5c06\u8981\u91c7\u53d6\u7684\u52a8\u4f5c\uff0c\u5e38\u89c1\u7684\u7528\u9014\u662f\u5728\u811a\u672c\u7a0b\u5e8f\u88ab\u4e2d\u65ad\u65f6\u5b8c\u6210\u6e05\u7406\u5de5\u4f5c\u3002\u5f53shell\u63a5\u6536\u5230sigspec\u6307\u5b9a\u7684\u4fe1\u53f7\u65f6\uff0carg\u53c2\u6570\uff08\u547d\u4ee4\uff09\u5c06\u4f1a\u88ab\u8bfb\u53d6\uff0c\u5e76\u88ab\u6267\u884c\u3002<\/p>\n\n\n\n

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

\u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n
-l<\/td>\u8ba9shell\u6253\u5370\u4e00\u4e2a\u547d\u4ee4\u540d\u79f0\u548c\u5176\u76f8\u5bf9\u5e94\u7684\u7f16\u53f7\u7684\u5217\u8868<\/td><\/tr>
-p<\/td>\u6253\u5370\u4e0e\u6bcf\u4e00\u4e2a\u4fe1\u53f7\u6709\u5173\u8054\u7684\u547d\u4ee4\u7684\u5217\u8868<\/td><\/tr>
\u7f3a\u7701<\/td>\u6bcf\u4e2a\u63a5\u6536\u5230\u7684sigspec\u4fe1\u53f7\u90fd\u5c06\u4f1a\u88ab\u91cd\u7f6e\u4e3a\u5b83\u4eec\u8fdb\u5165shell\u65f6\u7684\u503c<\/td><\/tr>
-f<\/td>\u963b\u6b62\u4e2d\u65ad\u4fe1\u53f7<\/td><\/tr><\/tbody><\/table>\n\n\n\n

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

\u6e05\u7406\u4e34\u65f6\u6587\u4ef6\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]$ trap \"rm -f $WORKDIR\/work1$ $WORKDIR\/dataout$; exit\" 2<\/pre>\n\n\n\n

\u5ffd\u7565\u4fe1\u53f7\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]$ trap '' 2<\/pre>\n\n\n\n

\u6062\u590d\u4fe1\u53f7\u7684\u9ed8\u8ba4\u64cd\u4f5c\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]$ trap 2<\/pre>\n\n\n\n

\u963b\u6b62\u4e2d\u65ad\u64cd\u4f5c\u4fe1\u53f7\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]$ tail -f \/var\/log\/test<\/pre>\n","protected":false},"excerpt":{"rendered":"

trap\u547d\u4ee4\u7528\u4e8e\u6307\u5b9a\u5728\u63a5\u6536\u5230\u4fe1\u53f7\u540e\u5c06\u8981\u91c7\u53d6\u7684\u52a8\u4f5c\uff0c\u5e38\u89c1\u7684\u7528\u9014\u662f\u5728\u811a\u672c\u7a0b\u5e8f\u88ab\u4e2d\u65ad\u65f6\u5b8c\u6210\u6e05\u7406\u5de5\u4f5c\u3002\u5f53shell\u63a5\u6536 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/4553"}],"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=4553"}],"version-history":[{"count":6,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/4553\/revisions"}],"predecessor-version":[{"id":4650,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/4553\/revisions\/4650"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=4553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=4553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=4553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}