<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nohup &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/nohup/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Tue, 03 Dec 2019 16:41:49 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>nohup &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>SSH 遠端登出後繼續執行</title>
		<link>https://noter.tw/3946/ssh-%e9%81%a0%e7%ab%af%e7%99%bb%e5%87%ba%e5%be%8c%e7%b9%bc%e7%ba%8c%e5%9f%b7%e8%a1%8c/</link>
					<comments>https://noter.tw/3946/ssh-%e9%81%a0%e7%ab%af%e7%99%bb%e5%87%ba%e5%be%8c%e7%b9%bc%e7%ba%8c%e5%9f%b7%e8%a1%8c/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sat, 09 Jun 2018 12:01:47 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[nohup]]></category>
		<category><![CDATA[screen]]></category>
		<guid isPermaLink="false">https://wazai.net/?p=3946</guid>

					<description><![CDATA[<p>昨天朋友問如果使用 PieTTY 遠端連線進主機，下了一個指令之後，這時候把 PieTTY 關掉，指令會不會繼續執行，還是關掉就斷掉了？小蛙之前也有類似的問題，問了精通 Linux 的同事後，同事給了&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3946/ssh-%e9%81%a0%e7%ab%af%e7%99%bb%e5%87%ba%e5%be%8c%e7%b9%bc%e7%ba%8c%e5%9f%b7%e8%a1%8c/" data-wpel-link="internal">SSH 遠端登出後繼續執行</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>昨天朋友問如果使用 PieTTY 遠端連線進主機，下了一個指令之後，這時候把 PieTTY 關掉，指令會不會繼續執行，還是關掉就斷掉了？小蛙之前也有類似的問題，問了精通 Linux 的同事後，同事給了一個 screen 的方法，小蛙記錄一下基本 screen 用法以及 Google 查到的其他用法。 </p>



<span id="more-3946"></span>



<h2 class="para wp-block-heading">使用 screen 讓指令繼續執行 </h2>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">screen
# 下你要的指令
ctrl + a, d</pre>



<p>這樣就可以斷線了，指令會繼續在背景執行。<br>常用指令如下，更詳細資訊可參考 <a rel="noreferrer noopener nofollow external" href="https://blog.longwin.com.tw/2005/11/screen_teach/" target="_blank" data-wpel-link="external" class="wpel-icon-right">screen 教學 @ Tsung&#8217;s Blog<span class="wpel-icon wpel-image wpel-icon-6"></span></a></p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code"># 進入 screen 環境
screen
# ctrl + a 即是進入命令模式
# 進入命令模式之後，後面接一個指令
# 開啟一個新視窗並切換到此視窗
ctrl + a, c
# 切換到下一個視窗
ctrl + a, n
# 切換到上一個使用的視窗，有點類似 cd - 切換到上一個工作目錄
ctrl + a, ctrl + a
# 顯示所有目前視窗，顯示結果如下 0$ bash  1-$ bash  2*$ bash
# * 表示目前使用視窗
ctrl + a, w
# 接續上述指令，可切換到該視窗
ctrl + a, 數字
# 另一個切換視窗的方法
ctrl + ', 數字
# 關閉目前視窗
ctrl + a, k
# 斷開 screen 並放背景執行
ctrl + a, d
# 查看目前 screen
screen -ls
26130.pts-0.xxxxx       (2018年06月09日 19時32分11秒)   (Detached)
25831.pts-0.xxxxx       (2018年06月09日 19時15分57秒)   (Detached)
# 接回 screen
screen -r 26130</pre>



<h2 class="para wp-block-heading">使用 nohup 指令 </h2>



<p>當從一個連線斷開的時候，系統會收到 SIGHUP 信號，如果使用 nohup 執行指令，則不會受到 SIGHUP 的影響繼續執行。 </p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code"># 以 nohup 執行並且加入「&amp;」丟到背景執行，執行的結果會存在 nohup.out
nohup xxxxxxxx &amp;</pre>



<p>20190307 額外補充 nohup 指令，因為小蛙要執行的指令會吐出一堆東西，而 nohup.out 檔案也會越來越大，但小蛙不想要有這個檔案(全看自己需求)。跟上個指令的差別在 &gt;/dev/null 2&gt;&amp;1 這樣就會把錯誤訊息跟執行時的訊息都捨棄 ~~</p>



<p>參考來源：<a rel="noreferrer noopener nofollow external" aria-label=" (在新分頁中開啟)" href="https://stackoverflow.com/questions/10408816/how-do-i-use-the-nohup-command-without-getting-nohup-out" target="_blank" data-wpel-link="external" class="wpel-icon-right">How do I use the nohup command without getting nohup.out?<span class="wpel-icon wpel-image wpel-icon-6"></span></a></p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">nohup command &gt; /dev/null 2&gt;&amp;1  
# doesn't create nohup.out

nohup command &gt;/dev/null 2&gt;&amp;1 &amp; 
# runs in background, still doesn't create nohup.out</pre>



<h2 class="para wp-block-heading">參考資料 </h2>



<ol class="my-li bg-darkblue wp-block-list"><li><a rel="noreferrer noopener nofollow external" href="https://blog.longwin.com.tw/2005/11/screen_teach/" target="_blank" data-wpel-link="external" class="wpel-icon-right">screen 教學 @ Tsung&#8217;s Blog<span class="wpel-icon wpel-image wpel-icon-6"></span></a></li><li><a href="http://dragonspring.pixnet.net/blog/post/33257496-%5Blinux%5Btips%5Dnohup%3A-%E8%AE%93command%E5%9C%A8%E9%81%A0%E7%AB%AF%E5%9F%B7%E8%A1%8C%EF%BC%8C%E4%B8%8D%E5%9B%A0%E7%99%BB%E5%87%BA" target="_blank" rel="noreferrer noopener nofollow external" aria-label="[linux[tips]nohup: 讓command在遠端執行，不因登出而中斷 @ 真實旅程 :: 痞客邦 :: (在新分頁中開啟)" data-wpel-link="external" class="wpel-icon-right">[linux[tips]nohup: 讓command在遠端執行，不因登出而中斷 @ 真實旅程 :: 痞客邦 ::<span class="wpel-icon wpel-image wpel-icon-6"></span></a></li><li><a rel="noreferrer noopener nofollow external" href="https://stackoverflow.com/questions/10408816/how-do-i-use-the-nohup-command-without-getting-nohup-out" target="_blank" data-wpel-link="external" class="wpel-icon-right">How do I use the nohup command without getting nohup.out?<span class="wpel-icon wpel-image wpel-icon-6"></span></a> </li></ol>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3946/ssh-%e9%81%a0%e7%ab%af%e7%99%bb%e5%87%ba%e5%be%8c%e7%b9%bc%e7%ba%8c%e5%9f%b7%e8%a1%8c/" data-wpel-link="internal">SSH 遠端登出後繼續執行</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/3946/ssh-%e9%81%a0%e7%ab%af%e7%99%bb%e5%87%ba%e5%be%8c%e7%b9%bc%e7%ba%8c%e5%9f%b7%e8%a1%8c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
