type Process struct {
Pid int
handle int
+ done bool // process has been successfuly waited on
}
func newProcess(pid, handle int) *Process {
- p := &Process{pid, handle}
+ p := &Process{Pid: pid, handle: handle}
runtime.SetFinalizer(p, (*Process).Release)
return p
}
if e != 0 {
return nil, NewSyscallError("wait", e)
}
+ if options&WSTOPPED == 0 {
+ p.done = true
+ }
w = new(Waitmsg)
w.Pid = pid1
w.WaitStatus = status
// Signal sends a signal to the Process.
func (p *Process) Signal(sig Signal) Error {
+ if p.done {
+ return NewError("os: process already finished")
+ }
if e := syscall.Kill(p.Pid, int(sig.(UnixSignal))); e != 0 {
return Errno(e)
}
if e != 0 {
return nil, NewSyscallError("GetExitCodeProcess", e)
}
+ p.done = true
return &Waitmsg{p.Pid, syscall.WaitStatus{s, ec}, new(syscall.Rusage)}, nil
}
// Signal sends a signal to the Process.
func (p *Process) Signal(sig Signal) Error {
+ if p.done {
+ return NewError("os: process already finished")
+ }
switch sig.(UnixSignal) {
case SIGKILL:
e := syscall.TerminateProcess(syscall.Handle(p.handle), 1)
var b bytes.Buffer
io.Copy(&b, r)
- p.Wait(0)
+ _, err = p.Wait(0)
+ if err != nil {
+ t.Fatalf("run hostname Wait: %v", err)
+ }
+ err = p.Kill()
+ if err == nil {
+ t.Errorf("expected an error from Kill running 'hostname'")
+ }
output := b.String()
if n := len(output); n > 0 && output[n-1] == '\n' {
output = output[0 : n-1]