fix pidfile writing