os.go 421 B

1234567891011121314151617181920
  1. package util
  2. import (
  3. "os"
  4. "path/filepath"
  5. )
  6. func WritePid() {
  7. pid := os.Getpid()
  8. file, err := os.OpenFile(filepath.Join(GetRootPath(), "app.pid"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
  9. if err != nil {
  10. Errorf("[WritePid] create app.pid find err, err=%v", err)
  11. return
  12. }
  13. _, err = file.Write([]byte(Int642String(int64(pid))))
  14. if err != nil {
  15. Errorf("[WritePid] write pid err, err=%v", err)
  16. return
  17. }
  18. }