Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

linux

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?

like image 582
Michael Avatar asked Jan 13 '23 15:01

Michael


2 Answers

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
like image 125
Petesh Avatar answered Jan 16 '23 20:01

Petesh


pid files are generally the location where applications store their process id, so the user can kill the process easily afterwards. These applications should be deleting these files when they close down.

I wouldn't worry about these files too much, unless you are seeing more and more of them and they dont get deleted, then it might be a tell tale sign that you have an application that is not shutting down correctly,

like image 44
Hendrik Avatar answered Jan 16 '23 21:01

Hendrik