<liclass="toctree-l4"><aclass="reference internal"href="#use-to-run-the-command-in-the-background">1. Use & to run the command in the background</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#list-background-jobs">2. List background jobs</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#suspend-and-cancel-job">3. Suspend and cancel job</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#fg-bg-switch-the-job-from-the-foreground-to-the-background-and-vise-verse">4. fg/bg, switch the job from the foreground to the background, and vise verse</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#redirect-the-output">5. Redirect the output</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/alibaba/arthas/issues?q=label%3Aquestion-answered">Questions and answers</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/alibaba/arthas">Fork me at GitHub</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md#">Compile and debug/CONTRIBUTING</a></li>
<p>Asynchronous jobs in arthas. The idea is borrowed from <aclass="reference external"href="http://man7.org/linux/man-pages/man1/jobs.1p.html">linux jobs</a>.</p>
<h2>1. Use & to run the command in the background<aclass="headerlink"href="#use-to-run-the-command-in-the-background"title="Permalink to this headline">¶</a></h2>
<h2>2. List background jobs<aclass="headerlink"href="#list-background-jobs"title="Permalink to this headline">¶</a></h2>
<p>If you want to list all background jobs, you can execute the <codeclass="docutils literal notranslate"><spanclass="pre">jobs</span></code> command and the results are as follows:</p>
<li><p>job id is 10, <codeclass="docutils literal notranslate"><spanclass="pre">*</span></code> indicates that this job is created by the current session.</p></li>
<li><p>status is <codeclass="docutils literal notranslate"><spanclass="pre">Stopped</span></code></p></li>
<li><p>execution count is the number of executions, which have been executed 19 times since the start.</p></li>
<li><p>timeout date: timeout timestamp, when the time exceeds this timestamp, the job will be automatically timeout and exit.</p></li>
<h2>3. Suspend and cancel job<aclass="headerlink"href="#suspend-and-cancel-job"title="Permalink to this headline">¶</a></h2>
<p>When the job is executing in the foreground, for example, directly executing the command <codeclass="docutils literal notranslate"><spanclass="pre">trace</span><spanclass="pre">Test</span><spanclass="pre">t</span></code>, or executing the background job command <codeclass="docutils literal notranslate"><spanclass="pre">trace</span><spanclass="pre">Test</span><spanclass="pre">t</span><spanclass="pre">&</span></code>, then putting the job back to the foreground via <codeclass="docutils literal notranslate"><spanclass="pre">fg</span></code> command, the console cannot continue to execute other command, but can receive and process the following keyboard events:</p>
<li><p>‘ctrl + z’: Suspend the job, the job status will change to <codeclass="docutils literal notranslate"><spanclass="pre">Stopped</span></code>, and the job can be restarted by <codeclass="docutils literal notranslate"><spanclass="pre">bg</span><spanclass="pre"><job-id></span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">fg</span><spanclass="pre"><job-id></span></code></p></li>
<li><p>‘ctrl + c’: Stop the job</p></li>
<li><p>‘ctrl + d’: According to linux semantics this should lead to exit the terminal, right now Arthas has not implemented this yet, therefore simply ignore this keystroke.</p></li>
<h2>4. fg/bg, switch the job from the foreground to the background, and vise verse<aclass="headerlink"href="#fg-bg-switch-the-job-from-the-foreground-to-the-background-and-vise-verse"title="Permalink to this headline">¶</a></h2>
<li><p>When a job is executed in the background or in suspended status (use <codeclass="docutils literal notranslate"><spanclass="pre">ctrl</span><spanclass="pre">+</span><spanclass="pre">z</span></code> to suspend job), <codeclass="docutils literal notranslate"><spanclass="pre">fg</span><spanclass="pre"><job-id></span></code> can transfer the job to the foreground to continue to run.</p></li>
<li><p>When a job is in suspended status (use <codeclass="docutils literal notranslate"><spanclass="pre">ctrl</span><spanclass="pre">+</span><spanclass="pre">z</span></code> to suspend job), <codeclass="docutils literal notranslate"><spanclass="pre">bg</span><spanclass="pre"><job-id></span></code> can put the job to the background to continue to run.</p></li>
<li><p>A job created by other session can only be put to the foreground to run by using <codeclass="docutils literal notranslate"><spanclass="pre">fg</span></code> in the current session.</p></li>
<h2>5. Redirect the output<aclass="headerlink"href="#redirect-the-output"title="Permalink to this headline">¶</a></h2>
<p>The job output can be redirect to the specified file by <codeclass="docutils literal notranslate"><spanclass="pre">></span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">>></span></code>, and can be used together with <codeclass="docutils literal notranslate"><spanclass="pre">&</span></code>. By doing this, you can achieve running commands asynchronously, for example:</p>
<divclass="highlight-bash notranslate"><divclass="highlight hljs"><preclass="bash">$ trace Test t >> test.out &</pre></div>
<p>The trace command will be running in the background and the output will be redirect to <codeclass="docutils literal notranslate"><spanclass="pre">~/logs/arthas-cache/test.out</span></code>. You can continue to execute other commands in the console, at the same time, you can also examine the execution result from the output file.</p>
<p>When connect to a remote Arthas server, you may not be able to view the output file on the remote machine. In this case, Arthas also supports automatically redirecting the output to the local cache file. Examples are as follows:</p>
<p>If output path is not given, Arthas will automatically redirect the output to the local cache. Job id and cache location will be shown on the console. Cache location is a directory where the output files are put. For one given job, the path of its output file contains PID and job id in order to avoid potential conflict with other jobs. In the above example, pid is <codeclass="docutils literal notranslate"><spanclass="pre">28198</span></code> and job id is <codeclass="docutils literal notranslate"><spanclass="pre">2</span></code>.</p>
<h2>6. Stop job<aclass="headerlink"href="#stop-job"title="Permalink to this headline">¶</a></h2>
<p>If you want to stop background job, just <codeclass="docutils literal notranslate"><spanclass="pre">kill</span><spanclass="pre"><job-id></span></code>.</p>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.