How to copy a thread dump using jstack command from EC2 instance in AWS?

0
1378

We can copy a thread dump from the EC2 instance by logging into the instance as super user by executing the below command using Cygwin terminal:-

sudo su -sam //Logged as super-user
[sam@student-server-111hared-i-074173501c09d2a88 ~]$$ jcmd 

The above command display the process Id 3695 of our server component running in EC2.

109067 sun.tools.jcmd.JCmd<br>3695 /projectname-deployable/145/runtime/jar/application/projectname-server-app-145.war

Using jstack command we would copy the thread dump of process 3695 by the below command:- 

jstack -l 3695 > /tmp/threaddump.txt // Copies under /tmp directory 
$ scp <instance-ip>:/tmp/threaddump.txt .  // This will copy the file to your local /Cygwin/home/<username> directory

If you get permission denied, then execute the below command from the logged-in EC2 instance box and re-try the above step by executing scp command to copy the file.

chmod 755 /tmp/threaddump.txt

Hope it helps!