import{_ as o,o as s,c,a as e,b as a,e as t,d as i,r as d}from"./app.6c27e557.js";const r={},l=e("h1",{id:"arthas-async-jobs",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#arthas-async-jobs","aria-hidden":"true"},"#"),t(" Arthas Async Jobs")],-1),u={href:"https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=case-async-jobs",target:"_blank",rel:"noopener noreferrer"},h=e("code",null,"Async Jobs",-1),p=t(" online tutorial"),b=t("Asynchronous jobs in arthas. The idea is borrowed from "),m={href:"http://man7.org/linux/man-pages/man1/jobs.1p.html",target:"_blank",rel:"noopener noreferrer"},g=t("linux jobs"),f=t("."),k=i(`

1. Use & to run the command in the background

For example, execute the trace command in the background:

trace Test t &

By doing this, the current command is put to the background to run, you can continue to execute other commands in the console.

2. List background jobs

If you want to list all background jobs, you can execute the jobs command and the results are as follows:

$ jobs
[10]*
       Stopped           watch com.taobao.container.Test test "params[0].{? #this.name == null }" -x 2
       execution count : 19
       start time      : Fri Sep 22 09:59:55 CST 2017
       timeout date    : Sat Sep 23 09:59:55 CST 2017
       session         : 3648e874-5e69-473f-9eed-7f89660b079b (current)

You can see that there is currently a background job executing:

3. Suspend and cancel job

When the job is executing in the foreground, for example, directly executing the command trace Test t, or executing the background job command trace Test t &, then putting the job back to the foreground via fg command, the console cannot continue to execute other command, but can receive and process the following keyboard events:

4. fg/bg, switch the job from the foreground to the background, and vise verse

5. Redirect the output

The job output can be redirect to the specified file by > or >>, and can be used together with &. By doing this, you can achieve running commands asynchronously, for example:

$ trace Test t >> test.out &

At this time, the trace command will be executed in the background, and the result will be output to the test.out file under the working directory 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 pwd command to view the working directory of the current application.

$ cat test.out

If no redirect file is specified, the result will be output to the ~/logs/arthas-cache/ directory, for example:

$ trace Test t >> &
job id : 2
cache location : /Users/admin/logs/arthas-cache/28198/2

At this time, the command will be executed asynchronously in the background, and the result will be asynchronously saved in the file (~/logs/arthas-cache/\${PID}/\${JobId});

6. Stop job

If you want to stop background job, just kill <job-id>.

7. Others

`,27);function v(x,j){const n=d("ExternalLinkIcon");return s(),c("div",null,[l,e("p",null,[e("a",u,[h,p,a(n)])]),e("p",null,[b,e("a",m,[g,a(n)]),f]),k])}const _=o(r,[["render",v],["__file","async.html.vue"]]);export{_ as default};