package os
import (
)
func ( *Process) () ( *ProcessState, error) {
if .Pid == -1 {
return nil, syscall.EINVAL
}
, := .blockUntilWaitable()
if != nil {
return nil,
}
if {
.setDone()
.sigMu.Lock()
.sigMu.Unlock()
}
var (
syscall.WaitStatus
syscall.Rusage
int
error
)
for {
, = syscall.Wait4(.Pid, &, 0, &)
if != syscall.EINTR {
break
}
}
if != nil {
return nil, NewSyscallError("wait", )
}
if != 0 {
.setDone()
}
= &ProcessState{
pid: ,
status: ,
rusage: &,
}
return , nil
}
func ( *Process) ( Signal) error {
if .Pid == -1 {
return errors.New("os: process already released")
}
if .Pid == 0 {
return errors.New("os: process not initialized")
}
.sigMu.RLock()
defer .sigMu.RUnlock()
if .done() {
return ErrProcessDone
}
, := .(syscall.Signal)
if ! {
return errors.New("os: unsupported signal type")
}
if := syscall.Kill(.Pid, ); != nil {
if == syscall.ESRCH {
return ErrProcessDone
}
return
}
return nil
}
func ( *Process) () error {
.Pid = -1
runtime.SetFinalizer(, nil)
return nil
}
func ( int) ( *Process, error) {
return newProcess(, 0), nil
}
func ( *ProcessState) () time.Duration {
return time.Duration(.rusage.Utime.Nano()) * time.Nanosecond
}
func ( *ProcessState) () time.Duration {
return time.Duration(.rusage.Stime.Nano()) * time.Nanosecond
}