</script><metaname="aes-config"content="pid=xux-opensource&user_type=101&uid=&username=&dim10=arthas"><scriptsrc="//g.alicdn.com/alilog/mlog/aplus_v2.js"id="beacon-aplus"exparams="clog=o&aplus&sidx=aplusSidx&ckx=aplusCkx"></script><scriptsrc="//g.alicdn.com/aes/??tracker/1.0.34/index.js,tracker-plugin-pv/2.4.5/index.js,tracker-plugin-event/1.2.5/index.js,tracker-plugin-jserror/1.0.13/index.js,tracker-plugin-api/1.1.14/index.js,tracker-plugin-perf/1.1.8/index.js,tracker-plugin-eventTiming/1.0.4/index.js"></script><title>Arthas Async Jobs | arthas</title><metaname="description"content="arthas user document">
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div></div></div><p>By doing this, the current command is put to the background to run, you can continue to execute other commands in the console.</p><h2id="_2-list-background-jobs"tabindex="-1"><aclass="header-anchor"href="#_2-list-background-jobs"aria-hidden="true">#</a> 2. List background jobs</h2><p>If you want to list all background jobs, you can execute the <code>jobs</code> command and the results are as follows:</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ <spanclass="token function">jobs</span>
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div></div></div><p>You can see that there is currently a background job executing:</p><ul><li>job id is 10, <code>*</code> indicates that this job is created by the current session.</li><li>status is <code>Stopped</code></li><li>execution count is the number of executions, which have been executed 19 times since the start.</li><li>timeout date: timeout timestamp, when the time exceeds this timestamp, the job will be automatically timeout and exit.</li></ul><h2id="_3-suspend-and-cancel-job"tabindex="-1"><aclass="header-anchor"href="#_3-suspend-and-cancel-job"aria-hidden="true">#</a> 3. Suspend and cancel job</h2><p>When the job is executing in the foreground, for example, directly executing the command <code>trace Test t</code>, or executing the background job command <code>trace Test t &</code>, then putting the job back to the foreground via <code>fg</code> command, the console cannot continue to execute other command, but can receive and process the following keyboard events:</p><ul><li>‘ctrl + z’: Suspends the job, the job status will change to <code>Stopped</code>, and the job can be restarted by <code>bg <job-id></code> or <code>fg <job-id></code></li><li>‘ctrl + c’: Stops the job</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></ul><h2id="_4-fg-bg-switch-the-job-from-the-foreground-to-the-background-and-vise-verse"tabindex="-1"><aclass="header-anchor"href="#_4-fg-bg-switch-the-job-from-the-foreground-to-the-background-and-vise-verse"aria-hidden="true">#</a> 4. fg/bg, switch the job from the foreground to the background, and vise verse</h2><ul><li>When a job is executed in the background or in suspended status (use <code>ctrl + z</code> to suspend job), <code>fg <job-id></code> can transfer the job to the foreground to continue to run.</li><li>When a job is in suspended status (use <code>ctrl + z</code> to suspend job), <code>bg <job-id></code> 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 <code>fg</code> in the current session.</li></ul><h2id="_5-redirect-the-output"tabindex="-1"><aclass="header-anchor"href="#_5-redirect-the-output"aria-hidden="true">#</a> 5. Redirect the output</h2><p>The job output can be redirect to the specified file by <code>></code> or <code>>></code>, and can be used together with <code>&</code>. By doing this, you can achieve running commands asynchronously, for example:</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ trace Test t <spanclass="token operator">>></span> test.out <spanclass="token operator">&</span>
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div></div></div><p>At this time, the trace command will be executed in the background, and the result will be output to the <code>test.out</code> file under the <code>working directory</code> of the application. You can continue to execute other commands. And you can view the command execution result in the file. You can execute the <code>pwd</code> command to view the <code>working directory</code> of the current application.</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ <spanclass="token function">cat</span> test.out
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div></div></div><p>If no redirect file is specified, the result will be output to the <code>~/logs/arthas-cache/</code> directory, for example:</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ trace Test t <spanclass="token operator">>></span><spanclass="token operator">&</span>
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div></div></div><p>At this time, the command will be executed asynchronously in the background, and the result will be asynchronously saved in the file (<code>~/logs/arthas-cache/${PID}/${JobId}</code>);</p><ul><li>At this time, the execution of the task is not affected by the session disconnection; the default timeout period of the task is 1 day, and the default timeout period can be modified through the global <code>options</code> command;</li><li>The result of this command will be output asynchronously to the file; at this time, regardless of whether <code>save-result</code> is true or not, the result will not be written asynchronously to <code>~/logs/arthas-cache/result.log</code>.</li></ul><h2id="_6-stop-job"tabindex="-1"><aclass="header-anchor"href="#_6-stop-job"aria-hidden="true">#</a> 6. Stop job</h2><p>If you want to stop background job, just <code>kill <job-id></code>.</p><h2id="_7-others"tabindex="-1"><aclass="header-anchor"href="#_7-others"aria-hidden="true">#</a> 7. Others</h2><ul><li>Support up to 8 commands at the same time to redirect the output to the log files.</li><li>Do not open too many background jobs at the same time to avoid negative performance effect to the target JVM.</li><li>If you do not want to stop the Arthas service and continue to perform background tasks, you can exit the Arthas console by executing <code>quit</code> command (<code>stop</code> command will stop the Arthas service)</li></ul></div><!--[--><!--]--></div><footerclass="page-meta right-menu-padding"data-v-fdd717e0><divclass="meta-item edit-link"><aclass="external-link meta-item-label"href="https://github.com/alibaba/arthas/edit/master/site/docs/en/doc/async.md"rel="noopener noreferrer"target="_blank"aria-label="Edit this page on GitHub"><!--[--><!--]--><span>Edit this page on GitHub</span><span><svgclass="external-link-icon"xmlns="http://www.w3.org/2000/svg"aria-hidden="true"focusable="false"x="0px"y="0px"viewbox="0 0 100 100"width="15"height="15"><pathfill="currentColor"d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygonfill="currentColor"points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><spanclass="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><divclass="meta-item last-updated"><spanclass="meta-item-label">Last Updated: </span><!----></div><divclass="meta-item contributors"><spanclass="meta-item-label">Contributors: </span><spanclass="meta-item-info"><!--[--><!--[--><spanclass="contributor"title="email: hengyunabc@gmail.com">hengyunabc</span><!--[-->, <!--]--><!--]--><!--[--><spanclass="contributor"title="email: 26602940+0xflotus@users.noreply.github.com">0xflotus</span><!--[-->, <!--]--><!--]--><!--[--><spanclass="contributor"title="email: arteevraina@gmail.com">Arteev Raina</span><!--[-->, <!--]--><!--]--><!--[--><spanclass="contributor"title="email: hollowman186@vip.qq.com">Hollow Man</span><!--[-->, <!--]--><!--]--><!--[--><spanclass="contributor"title="email: sergioescala@gmail.com">Sergio Escalante</span><!--[-->, <!--]--><!--]--><!--[--><spanclass="contributor"title="email: ian.luo@gmail.com">beiwei30</span><!--[-->, <!--]--><!--]--><!--[--><spanclass="contributor"title="email: 983433479@qq.com">汪吉</span><!----><!--]--><!--]--></span></div></footer><navclass="page-nav right-menu-padding"data-v-fdd717e0><pclass="inner"><!----><spanclass="next"><ahref="/en/doc/save-log.html"class=""aria-label="Log command outputs"><!--[--><!--]--> Log command outputs <!--[--><!--]--></a></span></p></nav><!--[--><!--]--></main><!--]--></div><!----><!--]--></div>