{"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":"
\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 |