Writes pid to a file. Is supposed to take an exclusive lock, but that's not working, and it's too late for me to understand why.