How to get rid of /tmp/.java_pid<number> files in Linux?

java, linux

Solution

These files are created by the JVM to support debugging. It's part of the `attach` api.

If you don't want java to create them then start java apps without debugging enabled.

You can safely delete them if there isn't a jvm with the corresponding pid... a task that is eminently suitable for a cron job.

A little bit of bash:

for file in /tmp/.java-[0-9]*; do
  [ -d /proc/${file#*.java-} ] || rm -f $file
done

Problem

I noticed a lot of file `/tmp/.java_pid<...>` in my Linux machine. The `file` command says they are sockets. Assuming they are created by Java I wonder why Java does not clean them up. How to make Java clean them up or just not create them?

Original source