If there is no `arthas-demo.jar` locally, you can download it from here:[Click](http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.taobao.arthas&a=arthas-boot&v=LATEST)
```
Save the contents above into `Demo.java`, then compile it under the command line:
You can also compile code by youself:[View](https://github.com/alibaba/arthas/blob/master/demo/src/main/java/demo)
```bash
javac Demo.java
java Demo
```
You can also save and start the code in IDE.
## 2. Start Arthas
## 2. Start Arthas
@ -55,30 +21,25 @@ You can also save and start the code in IDE.
Execute the following command in the command line:
Execute the following command in the command line:
```bash
```bash
./as.sh
java -jar arthas-boot.jar
```
```
> The user to run this script*MUST* have the same privilege as the owner of the target process, as a simple example you can try the following command if the target process is managed by user `admin`: `sudo su admin && ./as.sh` or `sudo -u admin -EH ./as.sh`. For more details on the bootstrap script, please refer to [Start Arthas](start-arthas.md). If you cannot be able to attach to the target process, please check the logs under `~/logs/arthas` for troubleshooting.
> The user to run this command*MUST* have the same privilege as the owner of the target process, as a simple example you can try the following command if the target process is managed by user `admin`: `sudo su admin && java -jar arthas-boot.jar` or `sudo -u admin -EH java -jar arthas-boot.jar`.If you cannot be able to attach to the target process, please check the logs under `~/logs/arthas` for troubleshooting.
Select the target Java process to attach:
Select the target Java process to attach:
```bash
```bash
$ ./as.sh
$ $ java -jar arthas-boot.jar
Arthas script version: 3.0.2
* [1]: 35542
Found existing java process, please choose one and hit RETURN.
[2]: 71560 arthas-demo.jar
* [1]: 95428
[2]: 22647 org.jetbrains.jps.cmdline.Launcher
[3]: 21736
[4]: 13560 Demo
```
```
The 'Demo' process is the fourth as shown above, press '4' then 'Enter'. Arthas will attach to the target process, and start to output:
The 'Demo' process is the fourth as shown above, press '2' then 'Enter'. Arthas will attach to the target process, and start to output:
```bash
```bash
Connecting to arthas server... current timestamp is 1536656867
[INFO] Try to attach process 71560
Trying 127.0.0.1...
[INFO] Attach process 71560 success.
Connected to 127.0.0.1.
[INFO] arthas-client connect 127.0.0.1 3658
Escape character is '^]'.
,---. ,------. ,--------.,--. ,--. ,---. ,---.
,---. ,------. ,--------.,--. ,--. ,---. ,---.
/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'
/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'
| .-. || '--'.' | | | .--. || .-. |`. `-.
| .-. || '--'.' | | | .--. || .-. |`. `-.
@ -87,15 +48,12 @@ Escape character is '^]'.
wiki: https://alibaba.github.io/arthas
wiki: https://alibaba.github.io/arthas
version: 3.0.1-RC-SNAPSHOT
version: 3.0.5.20181127201536
pid: 13560
pid: 71560
timestamp: 1536656867894
time: 2018-11-28 19:16:24
```
### Windows
Open 'Command' window, execute `as.bat <pid>` from where the Arthas package file is unzipped.
Pls. refer to [advanced usages](advanced-use.md) for more information.
Pls. refer to [advanced usages](advanced-use.md) for more information.
## 5. Exit Arthas
## 7. Exit Arthas
Use `quit` or `exit` to disconnect from the current process. The Arthas instance attached to the target process continues to live inside the process, and its port is standby for further connection.
Use `quit` or `exit` to disconnect from the current process. The Arthas instance attached to the target process continues to live inside the process, and its port is standby for further connection.