<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>
<spanid="arthas-async-jobs"></span><h1>Arthas Async Jobs<aclass="headerlink"href="#arthas-async-jobs"title="Permalink to this headline">¶</a></h1>
<p>Asynchronous jobs in arthas, using commands related to linux jobs.<aclass="reference external"href="http://man7.org/linux/man-pages/man1/jobs.1p.html">linux man 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>
<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>
<p>You can see that there is currently a background job executing.</p>
<ulclass="simple">
<li>job id is 10, <codeclass="docutils literal notranslate"><spanclass="pre">*</span></code> indicates that this job is created by the current session.</li>
<li>status is <codeclass="docutils literal notranslate"><spanclass="pre">Stopped</span></code></li>
<li>execution count is the number of executions, which have been executed 19 times since the start.</li>
<li>timeout date: After this time, the job will automatically timeout and exit.</li>
</ul>
</div>
<divclass="section"id="suspend-and-cannel-job">
<spanid="suspend-and-cannel-job"></span><h2>3. Suspend and Cannel job<aclass="headerlink"href="#suspend-and-cannel-job"title="Permalink to this headline">¶</a></h2>
<p>When the job is executing in the foreground, such as directly calling the command <codeclass="docutils literal notranslate"><spanclass="pre">trace</span><spanclass="pre">Test</span><spanclass="pre">t</span></code> or calling the background job command <codeclass="docutils literal notranslate"><spanclass="pre">trace</span><spanclass="pre">Test</span><spanclass="pre">t</span><spanclass="pre">&</span></code>, the job is transferred to the foreground through the <codeclass="docutils literal notranslate"><spanclass="pre">fg</span></code> command. At this point, the console cannot continue to execute the command, but can receive and process the following keyboard events:</p>
<ulclass="simple">
<li>‘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></li>
<li>‘ctrl + c’: Stop the job</li>
<li>‘ctrl + d’: According to linux semantics should be the exit terminal, currently arthas ignore this input.</li>
<spanid="fg-bg-bring-a-background-job-to-the-foreground-restart-a-stopped-background-job"></span><h2>4. fg/bg, Bring a background job to the foreground/Restart a stopped background job<aclass="headerlink"href="#fg-bg-bring-a-background-job-to-the-foreground-restart-a-stopped-background-job"title="Permalink to this headline">¶</a></h2>
<ulclass="simple">
<li>When the job is executed in the background or suspended (<codeclass="docutils literal notranslate"><spanclass="pre">ctrl</span><spanclass="pre">+</span><spanclass="pre">z</span></code> to suspend job), executing <codeclass="docutils literal notranslate"><spanclass="pre">fg</span><spanclass="pre"><job-id></span></code> will transfer the corresponding job to the foreground to continue execution.</li>
<li>When the job is suspended (<codeclass="docutils literal notranslate"><spanclass="pre">ctrl</span><spanclass="pre">+</span><spanclass="pre">z</span></code> to suspend job), executing <codeclass="docutils literal notranslate"><spanclass="pre">bg</span><spanclass="pre"><job-id></span></code> will continue the corresponding job in the background.</li>
<li>A job created by a non-current session can only be executed by the current session fg to the foreground.</li>
</ul>
</div>
<divclass="section"id="redirect-the-job-output">
<spanid="redirect-the-job-output"></span><h2>5. Redirect the job output<aclass="headerlink"href="#redirect-the-job-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> to implement the asynchronous job of the arthas command. such as:</p>
<p>The trace command will be executed 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.</p>
<p>When connecting to a remote arthas server, you may not be able to view the files of the remote machine. Arthas also supports automatic redirection to the local cache file. Examples are as follows:</p>
<p>You can see that does not specify the redirect file after <codeclass="docutils literal notranslate"><spanclass="pre">>></span></code>, arthas will automatically redirect the job output to the <codeclass="docutils literal notranslate"><spanclass="pre">~/logs/arthas-cache</span></code>.</p>
<p>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>
</div>
<divclass="section"id="stop-job">
<spanid="stop-job"></span><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>
</div>
<divclass="section"id="others">
<spanid="others"></span><h2>7. Others<aclass="headerlink"href="#others"title="Permalink to this headline">¶</a></h2>
<ulclass="simple">
<li>Support up to 8 commands at the same time redirect the output to the log file.</li>
<li>Do not open too many background asynchronous commands at the same time to avoid affecting the performance of the target JVM.</li>
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>.