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(`
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.
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:
*
indicates that this job is created by the current session.Stopped
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:
Stopped
, and the job can be restarted by bg <job-id>
or fg <job-id>
ctrl + z
to suspend job), fg <job-id>
can transfer the job to the foreground to continue to run.ctrl + z
to suspend job), bg <job-id>
can put the job to the background to continue to run.fg
in the current session.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}
);
options
command;save-result
is true or not, the result will not be written asynchronously to ~/logs/arthas-cache/result.log
.If you want to stop background job, just kill <job-id>
.
quit
command (stop
command will stop the Arthas service)