Search code examples
javalinuxheap-dumphprof

Give read permission to others for HeapDumpOnOutOfMemoryError file .hprof on generated


I start my java with these arguments

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/log/${SERVICE}_`date +%Y-%m-%d:%H:%M:%S`.hprof"

When heap dump occurs, the .hprof file has -rw------- (600) permission, which can't be read by other users.

How do I make these files generated with 644 permission?

Attempt: I tried passing this -XX:+HeapDumpOnOutOfMemoryError="chmod 644 *.hprof" but got the error:

Improperly specified VM option 'HeapDumpOnOutOfMemoryError=chmod'

What should be the correct syntax? Thank you


Solution

  • Found the issue, the correct args list should be

    -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='chmod 644 *.hprof' -XX:HeapDumpPath=/log/${SERVICE}_`date +%Y-%m-%d:%H:%M:%S`.hprof"
    

    Since I put everything inside double quote and then put in JAVA_OPTIONS, the inner quotes should be single