<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>
<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>
<spanid="use-to-run-the-command-in-the-background"></span><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>
<p>For example, execute the trace command in the background:</p>
<spanid="list-background-jobs"></span><h2>2. List background jobs<aclass="headerlink"href="#list-background-jobs"title="Permalink to this headline">¶</a></h2>
<spanid="suspend-and-cancel-job"></span><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 <ttclass="docutils literal">trace Test t</tt>, or executing the background job command <ttclass="docutils literal">trace Test t &</tt>, then putting the job back to the foreground via <ttclass="docutils literal">fg</tt> command, the console cannot continue to execute other command, but can receive and process the following keyboard events:</p>
<li>‘ctrl + z’: Suspend the job, the job status will change to <ttclass="docutils literal">Stopped</tt>, and the job can be restarted by <ttclass="docutils literal">bg <job-id></tt> or <ttclass="docutils literal">fg <job-id></tt></li>
<li>‘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.</li>
<spanid="fg-bg-switch-the-job-from-the-foreground-to-the-background-and-vise-verse"></span><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>When a job is executed in the background or in suspended status (use <ttclass="docutils literal">ctrl + z</tt> to suspend job), <ttclass="docutils literal">fg <job-id></tt> can transfer the job to the foreground to continue to run.</li>
<li>When a job is in suspended status (use <ttclass="docutils literal">ctrl + z</tt> to suspend job), <ttclass="docutils literal">bg <job-id></tt> can put the job to the background to continue to run.</li>
<li>A job created by other session can only be put to the foreground to run by using <ttclass="docutils literal">fg</tt> in the current session.</li>
<spanid="redirect-the-output"></span><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 <ttclass="docutils literal">></tt> or <ttclass="docutils literal">>></tt>, and can be used together with <ttclass="docutils literal">&</tt>. 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 &
<p>The trace command will be running in the background and the output will be redirect to <ttclass="docutils literal">~/logs/arthas-cache/test.out</tt>. 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 <ttclass="docutils literal">28198</tt> and job id is <ttclass="docutils literal">2</tt>.</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>.