1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
16 func (p
*Process
) wait() (ps
*ProcessState
, err error
) {
18 return nil, syscall
.EINVAL
21 // If we can block until Wait4 will succeed immediately, do so.
22 ready
, err
:= p
.blockUntilWaitable()
27 // Mark the process done now, before the call to Wait4,
28 // so that Process.signal will not send a signal.
30 // Acquire a write lock on sigMu to wait for any
31 // active call to the signal method to complete.
36 var status syscall
.WaitStatus
37 var rusage syscall
.Rusage
38 pid1
, e
:= syscall
.Wait4(p
.Pid
, &status
, 0, &rusage
)
40 return nil, NewSyscallError("wait", e
)
53 var errFinished
= errors
.New("os: process already finished")
55 func (p
*Process
) signal(sig Signal
) error
{
57 return errors
.New("os: process already released")
60 return errors
.New("os: process not initialized")
63 defer p
.sigMu
.RUnlock()
67 s
, ok
:= sig
.(syscall
.Signal
)
69 return errors
.New("os: unsupported signal type")
71 if e
:= syscall
.Kill(p
.Pid
, s
); e
!= nil {
72 if e
== syscall
.ESRCH
{
80 func (p
*Process
) release() error
{
83 // no need for a finalizer anymore
84 runtime
.SetFinalizer(p
, nil)
88 func findProcess(pid
int) (p
*Process
, err error
) {
90 return newProcess(pid
, 0), nil
93 func (p
*ProcessState
) userTime() time
.Duration
{
94 return time
.Duration(p
.rusage
.Utime
.Nano()) * time
.Nanosecond
97 func (p
*ProcessState
) systemTime() time
.Duration
{
98 return time
.Duration(p
.rusage
.Stime
.Nano()) * time
.Nanosecond