{"id":575,"date":"2017-07-24T20:01:10","date_gmt":"2017-07-24T12:01:10","guid":{"rendered":"https:\/\/blog.freesilo.com\/?p=575"},"modified":"2017-07-24T20:01:10","modified_gmt":"2017-07-24T12:01:10","slug":"%e4%bd%bf%e7%a8%8b%e5%ba%8f%e5%9c%a8linux%e4%b8%8b%e5%90%8e%e5%8f%b0%e8%bf%90%e8%a1%8c-%ef%bc%88%e5%85%b3%e6%8e%89%e7%bb%88%e7%ab%af%e7%bb%a7%e7%bb%ad%e8%ae%a9%e7%a8%8b%e5%ba%8f%e8%bf%90%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/freesilo.com\/?p=575","title":{"rendered":"\u4f7f\u7a0b\u5e8f\u5728Linux\u4e0b\u540e\u53f0\u8fd0\u884c \uff08\u5173\u6389\u7ec8\u7aef\u7ee7\u7eed\u8ba9\u7a0b\u5e8f\u8fd0\u884c\u7684\u65b9\u6cd5\uff09"},"content":{"rendered":"<p><span style=\"color: #ff0000;\"><strong>\u4e00\u3001\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7a0b\u5e8f\u5728\u540e\u53f0\u6267\u884c<\/strong><\/span><\/p>\n<p>\u6211\u4eec\u8ba1\u7b97\u7684\u7a0b\u5e8f\u90fd\u662f\u5468\u671f\u5f88\u957f\u7684\uff0c\u901a\u5e38\u8981\u51e0\u4e2a\u5c0f\u65f6\u751a\u81f3\u4e00\u4e2a\u661f\u671f\u3002\u6211\u4eec\u7528\u7684\u73af\u5883\u662f\u7528<span lang=\"EN-US\">putty\u8fdc\u7a0b\u8fde\u63a5\u5230\u65e5\u672cLinux\u670d\u52a1\u5668\u3002\u6240\u4ee5\u4f7f\u7a0b\u5e8f\u5728\u540e\u53f0\u8dd1\u6709\u4ee5\u4e0b\u4e09\u4e2a\u597d\u5904\uff1a<\/span><\/p>\n<p><span lang=\"EN-US\">1\uff1a\u6211\u4eec\u8fd9\u8fb9\u662f\u5426\u5173\u673a\u4e0d\u5f71\u54cd\u65e5\u672c\u90a3\u8fb9\u7684\u7a0b\u5e8f\u8fd0\u884c\u3002\uff08\u4e0d\u4f1a\u50cf\u4ee5\u524d\u90a3\u6837\uff0c\u6211\u4eec\u8fd9\u7f51\u7edc\u4e00\u65ad\u5f00\uff0c\u6216\u4e00\u5173\u673a\uff0c\u7a0b\u5e8f\u5c31\u65ad\u6389\u6216\u627e\u4e0d\u5230\u6570\u636e\uff0c\u8dd1\u4e86\u51e0\u5929\u7684\u7a0b\u5e8f\u53ea\u80fd\u91cd\u5934\u518d\u6765\uff0c\u5f88\u662f\u70e6\u607c\uff09<\/span><\/p>\n<p><span lang=\"EN-US\">2\uff1a\u4e0d\u5f71\u54cd\u8ba1\u7b97\u6548\u7387<\/span><\/p>\n<p><span lang=\"EN-US\">2\uff1a\u8ba9\u7a0b\u5e8f\u5728\u540e\u53f0\u8dd1\u540e\uff0c\u4e0d\u4f1a\u5360\u636e\u7ec8\u7aef\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u7ec8\u7aef\u505a\u522b\u7684\u4e8b\u60c5\u3002<\/span><\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u4e8c\u3001\u600e\u4e48\u6837\u4f7f\u7a0b\u5e8f\u5728\u540e\u53f0\u6267\u884c<\/strong><\/span><\/p>\n<p>\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u8fd9\u91cc\u4e3b\u8981\u5217\u4e3e\u4e24\u79cd\u3002\u5047\u5982\u6211\u4eec\u6709\u7a0b\u5e8f<span lang=\"EN-US\">pso.cpp,\u901a\u8fc7\u7f16\u8bd1\u540e\u4ea7\u751f\u53ef\u6267\u884c\u6587\u4ef6pso\uff0c\u6211\u4eec\u8981\u4f7fpso\u5728linux\u670d\u52a1\u5668\u540e\u53f0\u6267\u884c\u3002\u5f53\u5ba2\u6237\u7aef\u5173\u673a\u540e\u91cd\u65b0\u767b\u5165\u670d\u52a1\u5668\u540e\u7ee7\u7eed\u67e5\u770b\u672c\u6765\u5728\u7ec8\u7aef\u8f93\u51fa\u7684\u8fd0\u884c\u7ed3\u679c\u3002\uff08\u5047\u8bbe\u64cd\u4f5c\u90fd\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\uff09<\/span><\/p>\n<p><strong>\u65b9\u6cd5<span lang=\"EN-US\">1<\/span><\/strong><strong>\u5728\u7ec8\u7aef\u8f93\u5165\u547d\u4ee4\uff1a<\/strong><\/p>\n<p><span lang=\"EN-US\">\u00a0# .\/pso &gt; pso.file 2&gt;&amp;1 &amp;\u00a0<\/span><\/p>\n<p>\u89e3\u91ca\uff1a\u5c06<span lang=\"EN-US\">pso\u76f4\u63a5\u653e\u5728\u540e\u53f0\u8fd0\u884c\uff0c\u5e76\u628a\u7ec8\u7aef\u8f93\u51fa\u5b58\u653e\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u7684pso.file\u6587\u4ef6\u4e2d\u3002<\/span><\/p>\n<p><span lang=\"EN-US\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5f53\u5ba2\u6237\u7aef\u5173\u673a\u540e\u91cd\u65b0\u767b\u9646\u670d\u52a1\u5668\u540e\uff0c\u76f4\u63a5\u67e5\u770bpso.file\u6587\u4ef6\u5c31\u53ef\u770b\u6267\u884c\u7ed3\u679c\uff08\u547d<\/span><\/p>\n<p>\u4ee4\uff1a<span lang=\"EN-US\">#cat pso.file\u00a0\uff09\u3002<\/span><\/p>\n<p><span lang=\"EN-US\">\u00a0\u00a0<\/span><\/p>\n<p><strong>\u65b9\u6cd5<span lang=\"EN-US\">2<\/span><\/strong><strong>\u5728\u7ec8\u7aef\u8f93\u5165\u547d\u4ee4\uff1a<\/strong><\/p>\n<p><span lang=\"EN-US\"># nohup\u00a0 .\/pso &gt; pso.file 2&gt;&amp;1 &amp;<\/span><\/p>\n<p>\u89e3\u91ca\uff1a<span lang=\"EN-US\">nohup\u5c31\u662f\u4e0d\u6302\u8d77\u7684\u610f\u601d\uff0c\u5c06pso\u76f4\u63a5\u653e\u5728\u540e\u53f0\u8fd0\u884c\uff0c\u5e76\u628a\u7ec8\u7aef\u8f93\u51fa\u5b58\u653e\u5728\u5f53\u524d<\/span><\/p>\n<p>\u76ee\u5f55\u4e0b\u7684<span lang=\"EN-US\">pso.file\u6587\u4ef6\u4e2d\u3002\u5f53\u5ba2\u6237\u7aef\u5173\u673a\u540e\u91cd\u65b0\u767b\u9646\u670d\u52a1\u5668\u540e\uff0c\u76f4\u63a5\u67e5\u770bpso.file<\/span><\/p>\n<p>\u6587\u4ef6\u5c31\u53ef\u770b\u6267\u884c\u7ed3\u679c\uff08\u547d\u4ee4\uff1a<span lang=\"EN-US\">#cat pso.file\u00a0\uff09\u3002<\/span><\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u4e09\u3001\u5e38\u7528\u4efb\u52a1\u7ba1\u7406\u547d\u4ee4<\/strong><\/span><\/p>\n<p><span lang=\"EN-US\"># jobs\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u67e5\u770b\u4efb\u52a1\uff0c\u8fd4\u56de\u4efb\u52a1\u7f16\u53f7n\u548c\u8fdb\u7a0b\u53f7<\/span><\/p>\n<p><span lang=\"EN-US\"># bg\u00a0 %n\u00a0\u00a0 \/\/\u5c06\u7f16\u53f7\u4e3an\u7684\u4efb\u52a1\u8f6c\u540e\u53f0\u8fd0\u884c<\/span><\/p>\n<p><span lang=\"EN-US\"># fg\u00a0 %n\u00a0\u00a0 \/\/\u5c06\u7f16\u53f7\u4e3an\u7684\u4efb\u52a1\u8f6c\u524d\u53f0\u8fd0\u884c<\/span><\/p>\n<p><span lang=\"EN-US\"># ctrl+z\u00a0\u00a0\u00a0 \/\/\u6302\u8d77\u5f53\u524d\u4efb\u52a1<\/span><\/p>\n<p><span lang=\"EN-US\"># ctrl+c\u00a0\u00a0\u00a0 \/\/\u7ed3\u675f\u5f53\u524d\u4efb\u52a1<\/span><\/p>\n<p><span lang=\"EN-US\">\u00a0<\/span><\/p>\n<p>\u6ce8\uff1a\u5982\u679c\u8981\u4f7f\u5728\u524d\u5929\u6267\u884c\u4efb\u52a1\u653e\u5230\u540e\u53f0\u8fd0\u884c\uff0c\u5219\u5148\u8981\u7528<span lang=\"EN-US\">ctrl+z\u6302\u8d77\u8be5\u4efb\u52a1\uff0c\u7136\u540e\u7528bg\u4f7f\u4e4b\u540e\u53f0\u6267\u884c\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>\u9644\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p>\u5728Linux\u4e2d\uff0c\u5982\u679c\u8981\u8ba9\u8fdb\u7a0b\u5728\u540e\u53f0\u8fd0\u884c\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5728\u547d\u4ee4\u540e\u9762\u52a0\u4e0a&amp;\u5373\u53ef\uff0c\u5b9e\u9645\u4e0a\uff0c\u8fd9\u6837\u662f\u5c06\u547d\u4ee4\u653e\u5165\u5230\u4e00\u4e2a\u4f5c\u4e1a\u961f\u5217\u4e2d\u4e86\uff1a<\/p>\n<pre>$ .\/test.sh &amp; \r\n[1] 17208  \r\n$ jobs -l \r\n[1]+ 17208 Running                 .\/test.sh &amp;<\/pre>\n<p>\u5bf9\u4e8e\u5df2\u7ecf\u5728\u524d\u53f0\u6267\u884c\u7684\u547d\u4ee4\uff0c\u4e5f\u53ef\u4ee5\u91cd\u65b0\u653e\u5230\u540e\u53f0\u6267\u884c\uff0c\u9996\u5148\u6309<strong>ctrl+z<\/strong>\u6682\u505c\u5df2\u7ecf\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u7136\u540e\u4f7f\u7528<strong>bg<\/strong>\u547d\u4ee4\u5c06\u505c\u6b62\u7684\u4f5c\u4e1a\u653e\u5230\u540e\u53f0\u8fd0\u884c\uff1a<\/p>\n<pre>$ .\/test.sh \r\n[1]+  Stopped                 .\/test.sh  \r\n$ bg %1 [1]+ .\/test.sh &amp;  \r\n$ jobs -l \r\n[1]+ 22794 Running                 .\/test.sh &amp;<\/pre>\n<p>&nbsp;<\/p>\n<p>\u4f46\u662f\u5982\u4e0a\u65b9\u5230\u540e\u53f0\u6267\u884c\u7684\u8fdb\u7a0b\uff0c\u5176\u7236\u8fdb\u7a0b\u8fd8\u662f\u5f53\u524d\u7ec8\u7aefshell\u7684\u8fdb\u7a0b\uff0c\u800c\u4e00\u65e6\u7236\u8fdb\u7a0b\u9000\u51fa\uff0c\u5219\u4f1a\u53d1\u9001hangup\u4fe1\u53f7\u7ed9\u6240\u6709\u5b50\u8fdb\u7a0b\uff0c\u5b50\u8fdb\u7a0b\u6536\u5230hangup\u4ee5\u540e\u4e5f\u4f1a\u9000\u51fa\u3002\u5982\u679c\u6211\u4eec\u8981\u5728\u9000\u51fashell\u7684\u65f6\u5019\u7ee7\u7eed\u8fd0\u884c\u8fdb\u7a0b\uff0c\u5219\u9700\u8981\u4f7f\u7528<strong>nohup<\/strong>\u5ffd\u7565hangup\u4fe1\u53f7\uff0c\u6216\u8005<strong>setsid<\/strong>\u5c06\u5c06\u7236\u8fdb\u7a0b\u8bbe\u4e3ainit\u8fdb\u7a0b(\u8fdb\u7a0b\u53f7\u4e3a1)<\/p>\n<pre>$ echo $$ \r\n21734  \r\n$ nohup .\/test.sh &amp; \r\n[1] 29016  \r\n$ ps -ef | grep test \r\n515      29710 21734  0 11:47 pts\/12   00:00:00 \/bin\/sh .\/test.sh \r\n515      29713 21734  0 11:47 pts\/12   00:00:00 grep test<\/pre>\n<pre>$ setsid .\/test.sh &amp; \r\n[1] 409  \r\n$ ps -ef | grep test \r\n515        410     1  0 11:49 ?        00:00:00 \/bin\/sh .\/test.sh \r\n515        413 21734  0 11:49 pts\/12   00:00:00 grep test<\/pre>\n<p>\u4e0a\u9762\u7684\u8bd5\u9a8c\u6f14\u793a\u4e86\u4f7f\u7528nohup\/setsid\u52a0\u4e0a&amp;\u4f7f\u8fdb\u7a0b\u5728\u540e\u53f0\u8fd0\u884c\uff0c\u540c\u65f6\u4e0d\u53d7\u5f53\u524dshell\u9000\u51fa\u7684\u5f71\u54cd\u3002\u90a3\u4e48\u5bf9\u4e8e\u5df2\u7ecf\u5728\u540e\u53f0\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u8be5\u600e\u4e48\u529e\u5462\uff1f\u53ef\u4ee5\u4f7f\u7528<strong>disown<\/strong>\u547d\u4ee4\uff1a<\/p>\n<pre>$ .\/test.sh &amp; \r\n[1] 2539  \r\n$ jobs -l \r\n[1]+  2539 Running                 .\/test.sh &amp;  \r\n$ disown -h %1  \r\n$ ps -ef | grep test \r\n515        410     1  0 11:49 ?        00:00:00 \/bin\/sh .\/test.sh \r\n515       2542 21734  0 11:52 pts\/12   00:00:00 grep test<\/pre>\n<p>\u53e6\u5916\u8fd8\u6709\u4e00\u79cd\u65b9\u6cd5\uff0c\u5373\u4f7f\u5c06\u8fdb\u7a0b\u5728\u4e00\u4e2asubshell\u4e2d\u6267\u884c\uff0c\u5176\u5b9e\u8fd9\u548csetsid\u5f02\u66f2\u540c\u5de5\u3002\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u5c06\u547d\u4ee4\u7528\u62ec\u53f7() \u62ec\u8d77\u6765\u5373\u53ef\uff1a<\/p>\n<pre>$ (.\/test.sh &amp;)  \r\n$ ps -ef | grep test \r\n515        410     1  0 11:49 ?        00:00:00 \/bin\/sh .\/test.sh \r\n515      12483 21734  0 11:59 pts\/12   00:00:00 grep test<\/pre>\n<p>\u6ce8\uff1a\u672c\u6587\u8bd5\u9a8c\u73af\u5883\u4e3aRed Hat Enterprise Linux AS release 4 (Nahant Update 5),shell\u4e3a\/bin\/bash\uff0c\u4e0d\u540c\u7684OS\u548cshell\u53ef\u80fd\u547d\u4ee4\u6709\u4e9b\u4e0d\u4e00\u6837\u3002\u4f8b\u5982AIX\u7684ksh\uff0c\u6ca1\u6709disown\uff0c\u4f46\u662f\u53ef\u4ee5\u4f7f\u7528<strong>nohup -p\u00a0<em>PID<\/em><\/strong>\u6765\u83b7\u5f97disown\u540c\u6837\u7684\u6548\u679c\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u79cd\u66f4\u52a0\u5f3a\u5927\u7684\u65b9\u5f0f\u662f\u4f7f\u7528<strong>screen<\/strong>\uff0c\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u65ad\u5f00\u6a21\u5f0f\u7684\u865a\u62df\u7ec8\u7aef\uff0c\u7136\u540e\u7528-r\u9009\u9879\u91cd\u65b0\u8fde\u63a5\u8fd9\u4e2a\u865a\u62df\u7ec8\u7aef\uff0c\u5728\u5176\u4e2d\u6267\u884c\u7684\u4efb\u4f55\u547d\u4ee4\uff0c\u90fd\u80fd\u8fbe\u5230nohup\u7684\u6548\u679c\uff0c\u8fd9\u5728\u6709\u591a\u4e2a\u547d\u4ee4\u9700\u8981\u5728\u540e\u53f0\u8fde\u7eed\u6267\u884c\u7684\u65f6\u5019\u6bd4\u8f83\u65b9\u4fbf\uff1a<\/p>\n<pre>$ screen -dmS screen_test  \r\n$ screen -list There is a screen on:\r\n\u00a0             27963.screen_test       (Detached) 1 Socket in \/tmp\/uscreens\/S-jiangfeng.  \r\n$ screen -r screen_test \r\n\r\n\r\nFrom:https:\/\/www.cnblogs.com\/zhming26\/p\/6089928.html<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7a0b\u5e8f\u5728\u540e\u53f0\u6267\u884c \u6211\u4eec\u8ba1\u7b97\u7684\u7a0b\u5e8f\u90fd\u662f\u5468\u671f\u5f88\u957f\u7684\uff0c\u901a\u5e38\u8981\u51e0\u4e2a\u5c0f\u65f6\u751a\u81f3\u4e00&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/freesilo.com\/?p=575\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-575","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=575"}],"version-history":[{"count":2,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/575\/revisions"}],"predecessor-version":[{"id":580,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/575\/revisions\/580"}],"wp:attachment":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}