2019-04-21 11:50:48 +08:00

22 lines
2.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1 id="nohup">nohup</h1>
<p>将程序以忽略挂起信号的方式运行起来</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>nohup命令</strong> 可以将程序以忽略挂起信号的方式运行起来,被运行的程序的输出信息将不会显示到终端。</p>
<p>无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中。如果当前目录的 nohup.out 文件不可写,输出重定向到<code>$HOME/nohup.out</code>文件中。如果没有文件能创建或打开以用于追加,那么 command 参数指定的命令不可调用。如果标准错误是一个终端,那么把指定的命令写给标准错误的所有输出作为标准输出重定向到相同的文件描述符。</p>
<h3 id="语法">语法</h3>
<p>nohup(选项)(参数)</p>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">--help在线帮助
--version显示版本信息。</code></pre>
<h3 id="参数">参数</h3>
<p>程序及选项:要运行的程序及选项。</p>
<h3 id="实例">实例</h3>
<p>使用nohup命令提交作业如果使用nohup命令提交作业那么在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中除非另外指定了输出文件</p>
<pre><code class="language-bash">nohup command &gt; myout.file 2&gt;&amp;1 &amp;</code></pre>
<p>在上面的例子中输出被重定向到myout.file文件中。</p>
<p>该指令表示不做挂断操作,后台下载</p>
<div class="sourceCode" id="cb3"><pre><code class="language-bash"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="fu">nohup</span> wget site.com/file.zip</a></code></pre></div>
<p>下面命令,会在同一个目录下生成一个名称为 <code>nohup.out</code> 的文件,其中包含了正在运行的程序的输出内容</p>
<div class="sourceCode" id="cb4"><pre><code class="language-bash"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="fu">nohup</span> ping -c 10 baidu.com</a></code></pre></div>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->