pid.go 745 B

12345678910111213141516171819202122232425262728
  1. package namespaces
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "os"
  6. "path/filepath"
  7. )
  8. // WritePid writes the namespaced processes pid to pid and it's start time
  9. // to the path specified
  10. func WritePid(path string, pid int, startTime string) error {
  11. err := ioutil.WriteFile(filepath.Join(path, "pid"), []byte(fmt.Sprint(pid)), 0655)
  12. if err != nil {
  13. return err
  14. }
  15. return ioutil.WriteFile(filepath.Join(path, "start"), []byte(startTime), 0655)
  16. }
  17. // DeletePid removes the pid and started file from disk when the container's process
  18. // dies and the container is cleanly removed
  19. func DeletePid(path string) error {
  20. err := os.Remove(filepath.Join(path, "pid"))
  21. if serr := os.Remove(filepath.Join(path, "start")); err == nil {
  22. err = serr
  23. }
  24. return err
  25. }