os: replace non-portable Waitmsg with portable ProcessState
Use methods for key questions.
Provide access to non-portable pieces through portable methods.
Windows and Plan 9 updated.
R=golang-dev, bradfitz, bradfitz, r, dsymonds, rsc, iant, iant
CC=golang-dev
https://golang.org/cl/5673077
diff --git a/src/pkg/os/exec_unix.go b/src/pkg/os/exec_unix.go
index b9880ff..e5905f0 100644
--- a/src/pkg/os/exec_unix.go
+++ b/src/pkg/os/exec_unix.go
@@ -10,26 +10,30 @@
"errors"
"runtime"
"syscall"
+ "time"
)
// Wait waits for the Process to exit or stop, and then returns a
-// Waitmsg describing its status and an error, if any.
-func (p *Process) Wait() (w *Waitmsg, err error) {
+// ProcessState describing its status and an error, if any.
+func (p *Process) Wait() (ps *ProcessState, err error) {
if p.Pid == -1 {
return nil, syscall.EINVAL
}
var status syscall.WaitStatus
- pid1, e := syscall.Wait4(p.Pid, &status, 0, nil)
+ var rusage syscall.Rusage
+ pid1, e := syscall.Wait4(p.Pid, &status, 0, &rusage)
if e != nil {
return nil, NewSyscallError("wait", e)
}
if pid1 != 0 {
p.done = true
}
- w = new(Waitmsg)
- w.Pid = pid1
- w.WaitStatus = status
- return w, nil
+ ps = &ProcessState{
+ pid: pid1,
+ status: &status,
+ rusage: &rusage,
+ }
+ return ps, nil
}
// Signal sends a signal to the Process.
@@ -60,3 +64,13 @@
// NOOP for unix.
return newProcess(pid, 0), nil
}
+
+// UserTime returns the user CPU time of the exited process and its children.
+func (p *ProcessState) UserTime() time.Duration {
+ return time.Duration(p.rusage.Utime.Nano()) * time.Nanosecond
+}
+
+// SystemTime returns the system CPU time of the exited process and its children.
+func (p *ProcessState) SystemTime() time.Duration {
+ return time.Duration(p.rusage.Stime.Nano()) * time.Nanosecond
+}