How to remove orphaned PID files

Install an configure tacacs+ on Debian 8 – part 2
February 13, 2017
Linux SSH authentication with Google
December 22, 2017
Show all

How to remove orphaned PID files

According to a PID (proces identifier) is a number used by most operating system kernels — such as that of UNIX, macOS or Microsoft Windows — to uniquely identify an active process. This number may be used as a parameter in various function calls, allowing processes to be manipulated, such as adjusting the process’s priority or killing it altogether.

Some processes, for example, the moc music player and the MySQL daemon, write their PID to a documented file location, to allow other processes to look it up.

What to do in case, for some strange reason, that pid file never gets deleted when the process stops?

Well, 1st of all, you need to find out why that happens. However, this is not the reason I write this now.

In case the PID files are not deleted, although highly unlikely, it may happen that your hard drive will run out of space, so you need to find a way to remove those orphaned PID files.

A simple visual inspection of the directory containing the PID files ( e.g.  ls -ln /var/run/*.pid ) will show you all the PID files in /var/run/ directory.

If you have multiple PID files for the same process ( e.g.,, ecc. ) you may have a situation like the one described above.

So, how do you delete the PID files for the processes that are no longer running, without interfering with the running processes?

Check the below script:


Marin Nedea
Marin Nedea
I'm passionate about open source software and technologies. In my spare time I build simple and functional websites from scratch, using PHP+HTML5+CSS3+MySQL and when I'm bored, I write simple PHP_CLI or bash scripts to play around on my Linux machine.

Leave a Reply