I am running tomcat 5.5 on x86_64 CentOS 5.7 using 32-bit Oracle Java 1.6.0.
JVM process used by tomcat has 6421 pid. Tomcat is working fine.
When run
Probably the easiest way is:
see the owner of the process by ps -ef | grep "process name"
then switch to that user and run the command.
jcmd PID GC.run or any other java utility
One thing i noticed that nobody discussed here is; you also need to have JAVA_HOME variable set. check this by echo $JAVA_HOME
This is probably due to the file in /tmp used to communicate with the process having different permissions than the one the jstack gets. The file in question is /tmp/hsperfdata_$USER/$PID.
Don't know why it works with -F as the man page just says "Force a stack dump when 'jstack [-l] pid' does not respond."
I had this problem when i tried to run jstack
as root
.
Once i switched to another user it worked immediately.
To successfully use the jstack, you should be running it with the same user as the process.
If you don't want to worry about user and can work as root and are okay to kill the process, you could use this last resort:
kill -s SIGQUIT $PID
This will write the thread dump to your console log, for example, in case of Tomcat, that would require grepping for "Full Thread" that is the beginning of the thread dump in logs/catalina.out and then getting the tdump file as:
DUMP_IDX=`grep -n 'Full thread' logs/catalina.out | tail -1 | cut -d':' -f1`
sed -n $DUMP_IDX,1000000000000000000p logs/catalina.out > jstack-kill-thread-dump-0309.tdump
I was getting the same error running:
watch -n .5 "jstack 26259"
Doing as sudo it works:
sudo watch -n .5 "jstack 26259"