diff options
Diffstat (limited to 'libgo/go/os/exec_unix.go')
-rw-r--r-- | libgo/go/os/exec_unix.go | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/libgo/go/os/exec_unix.go b/libgo/go/os/exec_unix.go index 7fe7c2fe8cd..8d000e9ef15 100644 --- a/libgo/go/os/exec_unix.go +++ b/libgo/go/os/exec_unix.go @@ -10,46 +10,30 @@ import ( "errors" "runtime" "syscall" + "time" ) -// Options for Wait. -const ( - WNOHANG = syscall.WNOHANG // Don't wait if no process has exited. - WSTOPPED = syscall.WSTOPPED // If set, status of stopped subprocesses is also reported. - WUNTRACED = syscall.WUNTRACED // Usually an alias for WSTOPPED. - WRUSAGE = 1 << 20 // Record resource usage. -) - -// WRUSAGE must not be too high a bit, to avoid clashing with Linux's -// WCLONE, WALL, and WNOTHREAD flags, which sit in the top few bits of -// the options - // Wait waits for the Process to exit or stop, and then returns a -// Waitmsg describing its status and an error, if any. The options -// (WNOHANG etc.) affect the behavior of the Wait call. -func (p *Process) Wait(options int) (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, EINVAL + return nil, syscall.EINVAL } var status syscall.WaitStatus - var rusage *syscall.Rusage - if options&WRUSAGE != 0 { - rusage = new(syscall.Rusage) - options ^= WRUSAGE - } - pid1, e := syscall.Wait4(p.Pid, &status, options, rusage) + var rusage syscall.Rusage + pid1, e := syscall.Wait4(p.Pid, &status, 0, &rusage) if e != nil { return nil, NewSyscallError("wait", e) } - // With WNOHANG pid is 0 if child has not exited. - if pid1 != 0 && options&WSTOPPED == 0 { + if pid1 != 0 { p.done = true } - w = new(Waitmsg) - w.Pid = pid1 - w.WaitStatus = status - w.Rusage = rusage - return w, nil + ps = &ProcessState{ + pid: pid1, + status: status, + rusage: &rusage, + } + return ps, nil } // Signal sends a signal to the Process. @@ -80,3 +64,13 @@ func findProcess(pid int) (p *Process, err error) { // 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 +} |