{"id":2730,"date":"2016-06-07T20:29:46","date_gmt":"2016-06-07T12:29:46","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2730"},"modified":"2016-06-07T20:29:46","modified_gmt":"2016-06-07T12:29:46","slug":"linux%e4%b8%8b%e8%ae%a9%e8%bf%9b%e7%a8%8b%e5%9c%a8%e5%90%8e%e5%8f%b0%e5%8f%af%e9%9d%a0%e8%bf%90%e8%a1%8c%e7%9a%84%e5%87%a0%e7%a7%8d%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2730.html","title":{"rendered":"Linux\u4e0b\u8ba9\u8fdb\u7a0b\u5728\u540e\u53f0\u53ef\u9760\u8fd0\u884c\u7684\u51e0\u79cd\u65b9\u6cd5"},"content":{"rendered":"<p>=Start=<\/p>\n<h5>\u7f18\u7531\uff1a<\/h5>\n<p>\u6211\u7ecf\u5e38\u4f1a\u78b0\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u7528 ssh \u767b\u5f55\u4e86\u8fdc\u7a0b\u7684 Linux \u670d\u52a1\u5668\uff0c\u8fd0\u884c\u4e86\u4e00\u4e9b\u8017\u65f6\u8f83\u957f\u7684\u4efb\u52a1\uff0c\u7ed3\u679c\u5374\u7531\u4e8e\u7f51\u7edc\u7684\u4e0d\u7a33\u5b9a\u5bfc\u81f4\u4efb\u52a1\u4e2d\u9014\u5931\u8d25\u3002\u5982\u4f55\u8ba9\u547d\u4ee4\u63d0\u4ea4\u540e\u4e0d\u53d7\u672c\u5730\u5173\u95ed\u7ec8\u7aef\u7a97\u53e3\u3001\u7f51\u7edc\u65ad\u5f00\u8fde\u63a5\u7684\u5e72\u6270\u5462\uff1f\u603b\u7ed3\u4e0b\u6765\u4e3b\u8981\u6709\u4ee5\u4e0b3\u70b9\u9700\u6c42\uff1a<\/p>\n<ol>\n<li>\u60f3\u8ba9\u8fdb\u7a0b\u5728\u65ad\u5f00\u8fde\u63a5\u540e\u4f9d\u7136\u4fdd\u6301\u8fd0\u884c\uff1f<\/li>\n<li>\u5982\u679c\u8be5\u8fdb\u7a0b\u5df2\u7ecf\u5f00\u59cb\u8fd0\u884c\u4e86\u8be5\u5982\u4f55\u8865\u6551\uff1f<\/li>\n<li>\u5982\u679c\u6709\u5927\u91cf\u8fd9\u7c7b\u9700\u6c42\u5982\u4f55\u7b80\u5316\u64cd\u4f5c\uff1f<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u4e3b\u8981\u9488\u5bf9\u4ee5\u4e0a\u8fd93\u70b9\u9700\u6c42\u8fdb\u884c\u89e3\u7b54\uff0c\u5185\u5bb9\u57fa\u672c\u4e0a\u7167\u642c\u300c<a href=\"https:\/\/linux.cn\/article-7170-1.html?pr\">Linux \u4e0b\u8ba9\u8fdb\u7a0b\u5728\u540e\u53f0\u53ef\u9760\u8fd0\u884c\u7684\u51e0\u79cd\u65b9\u6cd5<\/a>\u300d\uff0c\u7565\u6709\u7cbe\u7b80\u3002<\/p>\n<h5>\u6b63\u6587\uff1a<\/h5>\n<h6>0x0.\u4e3a\u4ec0\u4e48SSH\u65ad\u5f00\u540e\u4f60\u8fd0\u884c\u7684\u8fdb\u7a0b\u4f1a\u9000\u51fa\u5462\uff1f<\/h6>\n<p>\u56e0\u4e3a\u6240\u6709\u8fdb\u7a0b\u90fd\u5f97\u6709\u4e2a\u7236\u8fdb\u7a0b\u3002\u5f53\u4f60ssh\u5230\u4e00\u4e2a\u670d\u52a1\u5668\u4e0a\u65f6\uff0c\u6253\u5f00\u7684shell\u5c31\u662f\u4f60\u6240\u6709\u6267\u884c\u547d\u4ee4\u7684\u7236\u8fdb\u7a0b\u3002<\/p>\n<p>\u5f53\u4f60\u65ad\u5f00ssh\u8fde\u63a5\u65f6\uff0c\u4f60\u7684\u547d\u4ee4\u7684\u7236\u8fdb\u7a0b\u5c31\u6ca1\u4e86\u3002\u5982\u679c\u5904\u7406\u4e0d\u5f53\uff0c\u8fd9\u4e9b\u8fdb\u7a0b\u5c31\u4f1a\u6536\u5230SIGTERM\u4fe1\u53f7\uff0c\u5168\u88ab\u5e72\u6389\u4e86\u3002<\/p>\n<h6>0x1.\u5982\u4f55\u8ba9\u8fdb\u7a0b\u5728\u65ad\u5f00SSH\u8fde\u63a5\u540e\u4f9d\u7136\u4fdd\u6301\u8fd0\u884c\uff1f<\/h6>\n<p><span style=\"color: #ff0000;\"><strong>nohup<\/strong><\/span> \u65e0\u7591\u662f\u6211\u4eec\u9996\u5148\u60f3\u5230\u7684\u529e\u6cd5\u3002\u987e\u540d\u601d\u4e49\uff0cnohup \u7684\u7528\u9014\u5c31\u662f\u8ba9\u63d0\u4ea4\u7684\u547d\u4ee4\u5ffd\u7565 hangup \u4fe1\u53f7\u3002<br \/>\nnohup \u7684\u4f7f\u7528\u662f\u5341\u5206\u65b9\u4fbf\u7684\uff0c\u53ea\u9700\u5728\u8981\u5904\u7406\u7684\u547d\u4ee4\u524d\u52a0\u4e0a nohup \u5373\u53ef\uff0c\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u7f3a\u7701\u4f1a\u88ab\u91cd\u5b9a\u5411\u5230 nohup.out \u6587\u4ef6\u4e2d\u3002\u4e00\u822c\u6211\u4eec\u53ef\u5728\u7ed3\u5c3e\u52a0\u4e0a&#8221;&amp;&#8221;\u6765\u5c06\u547d\u4ee4\u540c\u65f6\u653e\u5165\u540e\u53f0\u8fd0\u884c\uff0c\u4e5f\u53ef\u7528&#8221;&gt;filename 2&gt;&amp;1&#8243;\u6765\u66f4\u6539\u7f3a\u7701\u7684\u91cd\u5b9a\u5411\u6587\u4ef6\u540d\u3002<\/p>\n<p>nohup \u65e0\u7591\u80fd\u901a\u8fc7\u5ffd\u7565 HUP \u4fe1\u53f7\u6765\u4f7f\u6211\u4eec\u7684\u8fdb\u7a0b\u907f\u514d\u4e2d\u9014\u88ab\u4e2d\u65ad\uff0c\u4f46\u5982\u679c\u6211\u4eec\u6362\u4e2a\u89d2\u5ea6\u601d\u8003\uff0c\u5982\u679c\u6211\u4eec\u7684\u8fdb\u7a0b\u4e0d\u5c5e\u4e8e\u63a5\u53d7 HUP \u4fe1\u53f7\u7684\u7ec8\u7aef\u7684\u5b50\u8fdb\u7a0b\uff0c\u90a3\u4e48\u81ea\u7136\u4e5f\u5c31\u4e0d\u4f1a\u53d7\u5230 HUP \u4fe1\u53f7\u7684\u5f71\u54cd\u4e86\u3002setsid \u5c31\u80fd\u5e2e\u52a9\u6211\u4eec\u505a\u5230\u8fd9\u4e00\u70b9\u3002<br \/>\n<span style=\"color: #ff0000;\"><strong>setsid<\/strong><\/span> \u7684\u4f7f\u7528\u4e5f\u662f\u975e\u5e38\u65b9\u4fbf\u7684\uff0c\u4e5f\u53ea\u9700\u5728\u8981\u5904\u7406\u7684\u547d\u4ee4\u524d\u52a0\u4e0a setsid \u5373\u53ef\u3002<\/p>\n<p>\u5c06\u4e00\u4e2a\u6216\u591a\u4e2a\u547d\u540d\u5305\u542b\u5728\u201c()\u201d\u4e2d\u5c31\u80fd\u8ba9\u8fd9\u4e9b\u547d\u4ee4\u5728\u5b50 shell \u4e2d\u8fd0\u884c\u4e2d\uff0c\u540c\u65f6\u5c06&#8221;<span style=\"color: #ff0000;\"><strong>&amp;<\/strong><\/span>&#8220;\u4e5f\u653e\u5165\u201c()\u201d\u5185\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u4f1a\u53d1\u73b0\u65b0\u63d0\u4ea4\u7684\u8fdb\u7a0b\u7684\u7236ID\uff08PPID\uff09\u4e3a1\uff08init \u8fdb\u7a0b\u7684 PID\uff09\uff0c\u5e76\u4e0d\u662f\u5f53\u524d\u7ec8\u7aef\u7684\u8fdb\u7a0bID\u3002\u56e0\u6b64\u5e76\u4e0d\u5c5e\u4e8e\u5f53\u524d\u7ec8\u7aef\u7684\u5b50\u8fdb\u7a0b\uff0c\u6240\u4ee5\u80fd\u8eb2\u8fc7 HUP \u4fe1\u53f7\u7684\u5f71\u54cd\u3002<\/p>\n<h6>0x2.\u5982\u679c\u8be5\u8fdb\u7a0b\u5df2\u7ecf\u5f00\u59cb\u8fd0\u884c\u4e86\u8be5\u5982\u4f55\u8865\u6551\uff1f<\/h6>\n<p>\u53ea\u80fd\u901a\u8fc7 \u4f5c\u4e1a\u8c03\u5ea6(CTRL-z\/fg\/bg) \u548c disown \u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<h6>0x3.\u5982\u679c\u6709\u5927\u91cf\u8fd9\u7c7b\u9700\u6c42\u5982\u4f55\u7b80\u5316\u64cd\u4f5c\uff1f<\/h6>\n<p>\u5728 screen\/tmux\/byobu \u4e2d\u4efb\u9009\u4e00\u4e2a\u3002screen\/tmux\/byobu\u90fd\u662f\u865a\u62df\u591a\u7ec8\u7aef\u7684\u5de5\u5177\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5b8c\u6210\uff1a<\/p>\n<ol>\n<li>\u865a\u62df\u591a\u4e2a\u7ec8\u7aef\u5728\u4e00\u4e2assh\u8fde\u63a5\u4e2d\uff1b<\/li>\n<li>\u65ad\u7ebf\u540e\u7684\u6062\u590d\u3002<\/li>\n<\/ol>\n<p>\u8fd9\u91cc\u6211\u4eec\u9700\u8981\u7684\u662f\u7b2c2\u4e2a\u529f\u80fd\u3002<\/p>\n<h6>\u603b\u7ed3\uff1a<\/h6>\n<p>nohup\/setsid \u65e0\u7591\u662f\u4e34\u65f6\u9700\u8981\u65f6\u6700\u65b9\u4fbf\u7684\u65b9\u6cd5\uff0cdisown \u80fd\u5e2e\u52a9\u6211\u4eec\u6765\u4e8b\u540e\u8865\u6551\u5f53\u524d\u5df2\u7ecf\u5728\u8fd0\u884c\u4e86\u7684\u4f5c\u4e1a\uff0c\u800c screen\/tmux \u5219\u662f\u5728\u5927\u6279\u91cf\u64cd\u4f5c\u65f6\u4e0d\u4e8c\u7684\u9009\u62e9\u4e86\u3002<\/p>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"https:\/\/linux.cn\/article-7170-1.html?pr\">Linux \u4e0b\u8ba9\u8fdb\u7a0b\u5728\u540e\u53f0\u53ef\u9760\u8fd0\u884c\u7684\u51e0\u79cd\u65b9\u6cd5<\/a><\/li>\n<li><a href=\"http:\/\/www.linuxprobe.com\/process-run-background\/\">http:\/\/www.linuxprobe.com\/process-run-background\/<\/a><\/li>\n<li><a href=\"https:\/\/www.ibm.com\/developerworks\/cn\/linux\/l-cn-nohup\/\">https:\/\/www.ibm.com\/developerworks\/cn\/linux\/l-cn-nohup\/<\/a><\/li>\n<li><a href=\"http:\/\/seanlook.com\/2014\/02\/20\/linux-process-running-background-screen\/\">http:\/\/seanlook.com\/2014\/02\/20\/linux-process-running-background-screen\/<\/a><\/li>\n<li><a href=\"https:\/\/www.zhihu.com\/question\/20709809\">Linux ssh\u72b6\u6001\u4e0b\u5982\u4f55\u540e\u53f0\u8fd0\u884c\u7a0b\u5e8f\uff1f<\/a><\/li>\n<li><a href=\"https:\/\/segmentfault.com\/a\/1190000000349722\">Linux \u8fdb\u7a0b\u524d\u540e\u53f0\u5207\u6362|\u7ba1\u7406<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u6211\u7ecf\u5e38\u4f1a\u78b0\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u7528 ssh \u767b\u5f55\u4e86\u8fdc\u7a0b\u7684 Linux \u670d\u52a1\u5668\uff0c\u8fd0\u884c\u4e86\u4e00\u4e9b\u8017\u65f6\u8f83 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,7,12],"tags":[630,30,631,598,632],"class_list":["post-2730","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-programing","category-tools","tag-disown","tag-linux","tag-nohup","tag-screen","tag-sighup"],"views":4771,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2730"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2730\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}