WritePid.go 323 B

1234567891011121314151617181920
  1. package lib
  2. import (
  3. "bufio"
  4. "os"
  5. "strconv"
  6. )
  7. func WritePid() {
  8. fileName := "./server.pid"
  9. file, _ := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0666)
  10. defer file.Close()
  11. writer := bufio.NewWriter(file)
  12. pid := strconv.Itoa(os.Getpid())
  13. println("server_pid:", pid)
  14. writer.Write([]byte(pid))
  15. writer.Flush()
  16. }