To avoid issues with pidfiles being overwritten lock the file during modifications