{"id":85903,"date":"2023-12-29T05:43:03","date_gmt":"2023-12-28T21:43:03","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=85903"},"modified":"2023-12-29T05:43:03","modified_gmt":"2023-12-28T21:43:03","slug":"linux-vprocess-exit","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-vprocess-exit.html","title":{"rendered":"Linux\u8fdb\u7a0b\u9000\u51fa\u4e4b\u65b9\u6cd5\u8bba"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u7ed3\u675f\u4e86\u8fd0\u884c\u6216\u5728\u534a\u9014\u4e2d\u7ec8\u6b62\u4e86\u8fd0\u884c\uff0c\u90a3\u4e48\u5185\u6838\u5c31\u9700\u8981\u91ca\u653e\u8be5\u8fdb\u7a0b\u6240\u5360\u7528\u7684\u7cfb\u7edf\u8d44\u6e90\u3002\u8fd9\u5305\u62ec\u8fdb\u7a0b\u8fd0\u884c\u65f6\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u7533\u8bf7\u7684\u5185\u5b58\u7b49\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u8fdb\u7a0b\u9000\u51fa<\/strong><\/div>\n

Linux \u4e0b\u8fdb\u7a0b\u7684\u9000\u51fa\u5206\u4e3a\u6b63\u5e38\u9000\u51fa\u548c\u5f02\u5e38\u9000\u51fa\u4e24\u79cd:<\/p>\n

1.\u6b63\u5e38\u9000\u51fa<\/p>\n

a. \u5728main()\u51fd\u6570\u4e2d\u6267\u884creturn \u3002<\/p>\n

b.\u8c03\u7528exit()\u51fd\u6570<\/p>\n

c.\u8c03\u7528_exit()\u51fd\u6570<\/p>\n

2.\u5f02\u5e38\u9000\u51fa<\/p>\n

a.\u8c03\u7528about\u51fd\u6570<\/p>\n

b.\u8fdb\u7a0b\u6536\u5230\u67d0\u4e2a\u4fe1\u53f7\uff0c\u800c\u8be5\u4fe1\u53f7\u4f7f\u7a0b\u5e8f\u7ec8\u6b62\u3002<\/p>\n

\u4e0d\u7ba1\u662f\u54ea\u79cd\u9000\u51fa\u65b9\u5f0f\uff0c\u7cfb\u7edf\u6700\u7ec8\u90fd\u4f1a\u6267\u884c\u5185\u6838\u4e2d\u7684\u540c\u4e00\u4ee3\u7801\u3002\u8fd9\u6bb5\u4ee3\u7801\u7528\u6765\u5173\u95ed\u8fdb\u7a0b\u6240\u7528\u5df2\u6253\u5f00\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u91ca\u653e\u5b83\u6240\u5360\u7528\u7684\u5185\u5b58\u548c\u5176\u4ed6\u8d44\u6e90\u3002<\/p>\n

\u51e0\u79cd\u9000\u51fa\u65b9\u5f0f\u7684\u6bd4\u8f83<\/strong><\/div>\n

1.exit\u548creturn \u7684\u533a\u522b\uff1a<\/p>\n

exit\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u6709\u53c2\u6570\u3002exit\u6267\u884c\u5b8c\u540e\u628a\u63a7\u5236\u6743\u4ea4\u7ed9\u7cfb\u7edf<\/p>\n

return\u662f\u51fd\u6570\u6267\u884c\u5b8c\u540e\u7684\u8fd4\u56de\u3002renturn\u6267\u884c\u5b8c\u540e\u628a\u63a7\u5236\u6743\u4ea4\u7ed9\u8c03\u7528\u51fd\u6570\u3002<\/p>\n

2.exit\u548cabort\u7684\u533a\u522b\uff1a<\/p>\n

exit\u662f\u6b63\u5e38\u7ec8\u6b62\u8fdb\u7a0b<\/p>\n

about\u662f\u5f02\u5e38\u7ec8\u6b62\u3002<\/p>\n

exit()\u548c_exit()\u51fd\u6570<\/strong><\/div>\n

exit\u548c_exit\u51fd\u6570\u90fd\u662f\u7528\u6765\u7ec8\u6b62\u8fdb\u7a0b\u7684\u3002\u5f53\u7a0b\u5e8f\u6267\u884c\u5230exit\u6216_exit\u65f6\uff0c\u7cfb\u7edf\u65e0\u6761\u4ef6\u7684\u505c\u6b62\u5269\u4e0b\u6240\u6709\u64cd\u4f5c\uff0c\u6e05\u9664\u5404\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5e76\u7ec8\u6b62\u672c\u8fdb\u7a0b\u7684\u8fd0\u884c\u3002<\/p>\n

exit\u5728\u5934\u6587\u4ef6stdlib.h\u4e2d\u58f0\u660e\uff0c\u800c_exit()\u58f0\u660e\u5728\u5934\u6587\u4ef6unistd.h\u4e2d\u58f0\u660e\u3002 exit\u4e2d\u7684\u53c2\u6570exit_code\u4e3a\uff10\u4ee3\u8868\u8fdb\u7a0b\u6b63\u5e38\u7ec8\u6b62\uff0c\u82e5\u4e3a\u5176\u4ed6\u503c\u8868\u793a\u7a0b\u5e8f\u6267\u884c\u8fc7\u7a0b\u4e2d\u6709\u9519\u8bef\u53d1\u751f\u3002<\/p>\n

exit()\u548c_exit()\u7684\u533a\u522b<\/strong><\/div>\n

_exit()\u6267\u884c\u540e\u7acb\u5373\u8fd4\u56de\u7ed9\u5185\u6838\uff0c\u800cexit()\u8981\u5148\u6267\u884c\u4e00\u4e9b\u6e05\u9664\u64cd\u4f5c\uff0c\u7136\u540e\u5c06\u63a7\u5236\u6743\u4ea4\u7ed9\u5185\u6838\u3002<\/p>\n

\u8c03\u7528_exit\u51fd\u6570\u65f6\uff0c\u5176\u4f1a\u5173\u95ed\u8fdb\u7a0b\u6240\u6709\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u6e05\u7406\u5185\u5b58\u4ee5\u53ca\u5176\u4ed6\u4e00\u4e9b\u5185\u6838\u6e05\u7406\u51fd\u6570\uff0c\u4f46\u4e0d\u4f1a\u5237\u65b0\u6d41(stdin, stdout, stderr ...). exit\u51fd\u6570\u662f\u5728_exit\u51fd\u6570\u4e4b\u4e0a\u7684\u4e00\u4e2a\u5c01\u88c5\uff0c\u5176\u4f1a\u8c03\u7528_exit\uff0c\u5e76\u5728\u8c03\u7528\u4e4b\u524d\u5148\u5237\u65b0\u6d41\u3002<\/p>\n

exit()\u51fd\u6570\u4e0e_exit()\u51fd\u6570\u6700\u5927\u533a\u522b\u5c31\u5728\u4e8eexit()\u51fd\u6570\u5728\u8c03\u7528exit\u7cfb\u7edf\u4e4b\u524d\u8981\u68c0\u67e5\u6587\u4ef6\u7684\u6253\u5f00\u60c5\u51b5\uff0c\u628a\u6587\u4ef6\u7f13\u51b2\u533a\u7684\u5185\u5bb9\u5199\u56de\u6587\u4ef6\u3002\u7531\u4e8eLinux\u7684\u6807\u51c6\u51fd\u6570\u5e93\u4e2d\uff0c\u6709\u4e00\u79cd\u88ab\u79f0\u4f5c\u201c\u7f13\u51b2I\/O\u201d\u7684\u64cd\u4f5c\uff0c\u5176\u7279\u5f81\u5c31\u662f\u5bf9\u5e94\u6bcf\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u5728\u5185\u5b58\u4e2d\u90fd\u6709\u4e00\u7247\u7f13\u51b2\u533a\u3002\u6bcf\u6b21\u8bfb\u6587\u4ef6\u65f6\uff0c\u4f1a\u8fde\u7eed\u7684\u8bfb\u51fa\u82e5\u5e72\u6761\u8bb0\u5f55\uff0c\u8fd9\u6837\u5728\u4e0b\u6b21\u8bfb\u6587\u4ef6\u65f6\u5c31\u53ef\u4ee5\u76f4\u63a5\u4ece\u5185\u5b58\u7684\u7f13\u51b2\u533a\u8bfb\u53d6\uff1b\u540c\u6837\uff0c\u6bcf\u6b21\u5199\u6587\u4ef6\u7684\u65f6\u5019\u4e5f\u4ec5\u4ec5\u662f\u5199\u5165\u5185\u5b58\u7684\u7f13\u51b2\u533a\uff0c\u7b49\u6ee1\u8db3\u4e86\u4e00\u5b9a\u7684\u6761\u4ef6\uff08\u5982\u8fbe\u5230\u4e86\u4e00\u5b9a\u6570\u91cf\u6216\u9047\u5230\u7279\u5b9a\u5b57\u7b26\u7b49\uff09\uff0c\u518d\u5c06\u7f13\u51b2\u533a\u4e2d\u7684\u5185\u5bb9\u4e00\u6b21\u6027\u5199\u5165\u6587\u4ef6\u3002\u8fd9\u79cd\u6280\u672f\u5927\u5927\u589e\u52a0\u4e86\u6587\u4ef6\u8bfb\u5199\u7684\u901f\u5ea6\uff0c\u4f46\u4e5f\u7ed9\u7f16\u7a0b\u4ee3\u6765\u4e86\u4e00\u70b9\u513f\u9ebb\u70e6\u3002\u6bd4\u5982\u6709\u4e00\u4e9b\u6570\u636e\uff0c\u8ba4\u4e3a\u5df2\u7ecf\u5199\u5165\u4e86\u6587\u4ef6\uff0c\u5b9e\u9645\u4e0a\u56e0\u4e3a\u6ca1\u6709\u6ee1\u8db3\u7279\u5b9a\u7684\u6761\u4ef6\uff0c\u5b83\u4eec\u8fd8\u53ea\u662f\u4fdd\u5b58\u5728\u7f13\u51b2\u533a\u5185\uff0c\u8fd9\u65f6\u7528_exit()\u51fd\u6570\u76f4\u63a5\u5c06\u8fdb\u7a0b\u5173\u95ed\uff0c\u7f13\u51b2\u533a\u7684\u6570\u636e\u5c31\u4f1a\u4e22\u5931\u3002\u56e0\u6b64\uff0c\u8981\u60f3\u4fdd\u8bc1\u6570\u636e\u7684\u5b8c\u6574\u6027\uff0c\u5c31\u4e00\u5b9a\u8981\u4f7f\u7528exit()\u51fd\u6570\u3002<\/p>\n

\u901a\u8fc7\u4e00\u4e2a\u51fd\u6570\u5b9e\u4f8b\u6765\u770b\u770b\u5b83\u4eec\u4e4b\u95f4\u7684\u533a\u522b\uff1a<\/p>\n

\u51fd\u6570\u5b9e\u4f8b1 \uff1a exit.c<\/p>\n

#include\r\n#include\r\n\r\nint main()\r\n{\r\nprintf(\"using exit----\\n\");\r\nprintf(\"This is the content in buffer\\n\");\r\nexit(0);\r\n}\r\n<\/pre>\n

\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n

using exit----\r\n\r\nThis is the content in buffer\r\n<\/pre>\n

\u51fd\u6570\u5b9e\u4f8b2\uff1a_exit.c<\/p>\n

#include\r\n#include\r\n\r\nint main()\r\n{\r\nprintf(\"using _exit--\\n\");\r\nprintf(\"This is the content in buffer\");\r\n_exit(0);\r\n}\r\n<\/pre>\n

\u6267\u884c\u7ed3\u679c\u4e3a \uff1a<\/p>\n

using _exit--\r\n<\/pre>\n

printf\u51fd\u6570\u5c31\u662f\u4f7f\u7528\u7f13\u51b2I\/O\u7684\u65b9\u5f0f\uff0c\u8be5\u51fd\u6570\u5728\u9047\u5230\u201c\\n\u201d\u6362\u884c\u7b26\u65f6\u81ea\u52a8\u7684\u4ece\u7f13\u51b2\u533a\u4e2d\u5c06\u8bb0\u5f55\u8bfb\u51fa\u3002\u6240\u4ee5exit()\u5c06\u7f13\u51b2\u533a\u7684\u6570\u636e\u5199\u5b8c\u540e\u624d\u9000\u51fa\uff0c\u800c_exit()\u51fd\u6570\u76f4\u63a5\u9000\u51fa\u3002<\/p>\n

\u5927\u5bb6\u4e5f\u53ef\u4ee5\u628a\u51fd\u6570\u5b9e\u4f8b2\u4e2d\u7684printf(\"This is the content in buffer\");\u6539\u4e3aprintf(\"This is the content in buffer\\n\")(\u5373\u5728printf\u4e2d\u6700\u540e\u52a0\u4e00\u4e2a\\n\u770b\u8fd0\u884c\u7ed3\u679c\u662f\u4ec0\u4e48\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u4ea7\u751f\u8fd9\u6837\u7684\u7ed3\u679c\u5462\uff1f)<\/p>\n

\u7236\u5b50\u8fdb\u7a0b\u7ec8\u6b62\u7684\u5148\u540e\u987a\u5e8f\u4e0d\u540c\u4f1a\u4ea7\u751f\u4e0d\u540c\u7684\u7ed3\u679c<\/strong><\/div>\n

1.\u7236\u8fdb\u7a0b\u5148\u4e8e\u5b50\u8fdb\u7a0b\u7ec8\u6b62\uff1a<\/p>\n

\u6b64\u79cd\u60c5\u51b5\u5c31\u662f\u6211\u4eec\u524d\u9762\u6240\u7528\u7684\u5b64\u513f\u8fdb\u7a0b\u3002\u5f53\u7236\u8fdb\u7a0b\u5148\u9000\u51fa\u65f6\uff0c\u7cfb\u7edf\u4f1a\u8ba9init\u8fdb\u7a0b\u63a5\u7ba1\u5b50\u8fdb\u7a0b \u3002<\/p>\n

2.\u5b50\u8fdb\u7a0b\u5148\u4e8e\u7236\u8fdb\u7a0b\u7ec8\u6b62\uff0c\u800c\u7236\u8fdb\u7a0b\u53c8\u6ca1\u6709\u8c03\u7528wait\u51fd\u6570<\/p>\n

\u6b64\u79cd\u60c5\u51b5\u5b50\u8fdb\u7a0b\u8fdb\u5165\u50f5\u6b7b\u72b6\u6001\uff0c\u5e76\u4e14\u4f1a\u4e00\u76f4\u4fdd\u6301\u4e0b\u53bb\u76f4\u5230\u7cfb\u7edf\u91cd\u542f\u3002\u5b50\u8fdb\u7a0b\u5904\u4e8e\u50f5\u6b7b\u72b6\u6001\u65f6\uff0c\u5185\u6838\u53ea\u4fdd\u5b58\u8fdb\u7a0b\u7684\u4e00\u4e9b\u5fc5\u8981\u4fe1\u606f\u4ee5\u5907\u7236\u8fdb\u7a0b\u6240\u9700\u3002\u6b64\u65f6\u5b50\u8fdb\u7a0b\u59cb\u7ec8\u5360\u6709\u7740\u8d44\u6e90\uff0c\u540c\u65f6\u4e5f\u51cf\u5c11\u4e86\u7cfb\u7edf\u53ef\u4ee5\u521b\u5efa\u7684\u6700\u5927\u8fdb\u7a0b\u6570\u3002<\/p>\n

\u4ec0\u4e48\u662f \u50f5\u6b7b\u72b6\u6001\u5462\uff1f<\/p>\n

\u4e00\u4e2a\u5df2\u7ecf\u7ec8\u6b62\u3001\u4f46\u662f\u5176\u7236\u8fdb\u7a0b\u5c1a\u672a\u5bf9\u5176\u8fdb\u884c\u5584\u540e\u5904\u7406(\u83b7\u53d6\u7ec8\u6b62\u5b50\u8fdb\u7a0b\u7684\u6709\u5173\u4fe1\u606f\uff0c\u91ca\u653e\u5b83\u4ecd\u5360\u6709\u7684\u8d44\u6e90)\u7684\u8fdb\u7a0b\u88ab\u79f0\u4e3a\u50f5\u6b7b\u8fdb\u7a0b(zombie)\u3002<\/p>\n

3.\u5b50\u8fdb\u7a0b\u5148\u4e8e\u7236\u8fdb\u7a0b\u7ec8\u6b62\uff0c\u800c\u7236\u8fdb\u7a0b\u8c03\u7528\u4e86wait\u51fd\u6570<\/p>\n

\u6b64\u65f6\u7236\u8fdb\u7a0b\u4f1a\u7b49\u5f85\u5b50\u8fdb\u7a0b\u7ed3\u675f\u3002<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.cnblogs.com\/chay\/p\/7678152.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/linux-vprocess-exit.html<\/a>\u7f16\u8f91\uff1a\u90d1\u5e05\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u5f53\u4e00\u4e2a\u8fdb\u7a0b\u7ed3\u675f\u4e86\u8fd0\u884c\u6216\u5728\u534a\u9014\u4e2d\u7ec8\u6b62\u4e86\u8fd0\u884c\uff0c\u90a3\u4e48\u5185\u6838\u5c31\u9700\u8981\u91ca\u653e\u8be5\u8fdb\u7a0b\u6240\u5360\u7528\u7684\u7cfb\u7edf\u8d44\u6e90\u3002\u8fd9\u5305\u62ec\u8fdb\u7a0b\u8fd0\u884c\u65f6\u6253\u5f00 […]<\/p>\n","protected":false},"author":63,"featured_media":85906,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-85903","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\/85903","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\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=85903"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/85903\/revisions"}],"predecessor-version":[{"id":85925,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/85903\/revisions\/85925"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/85906"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=85903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=85903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=85903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}