This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a pid file, but first make sure it doesn't exist with a running pid. | |
func writePidFile(pidFile string) error { | |
// Read in the pid file as a slice of bytes. | |
if piddata, err := ioutil.ReadFile(pidFile); err == nil { | |
// Convert the file contents to an integer. | |
if pid, err := strconv.Atoi(string(piddata)); err == nil { | |
// Look for the pid in the process list. | |
if process, err := os.FindProcess(pid); err == nil { | |
// Send the process a signal zero kill. | |
if err := process.Signal(syscall.Signal(0)); err == nil { |