jstack - well-known file is not secure

Solution 1:

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."

Solution 2:

when -F is used, the jvm will be frozen.

If you can find the file: /tmp/hsperfdata_$USER/$PID. Just try to switch to the $USER, and then exec jstack. You are running with "root", but that process may not belong to root.

if $USER does not have a login shell (i.e. daemon users), and thus can not switch to that user, you can work around this by using sudo -u $USER jstack $PID

Solution 3:

I had this problem when i tried to run jstack as root.

Once i switched to another user it worked immediately.

Solution 4:

I just would like to add that you might need to specify your /tmp directory by -J option, since not all apps use the the default one

jstack -J-Djava.io.tmpdir=PATH -l PID

Solution 5:

I was getting the same error running:

watch -n .5 "jstack 26259"

Doing as sudo it works:

sudo watch -n .5 "jstack 26259"