S/390: Fix vector all/any cc modes.
[official-gcc.git] / libgo / go / os / exec_unix.go
blobc4999db57f09051e9111199f429018cdf3871509
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
7 package os
9 import (
10 "errors"
11 "runtime"
12 "syscall"
13 "time"
16 func (p *Process) wait() (ps *ProcessState, err error) {
17 if p.Pid == -1 {
18 return nil, syscall.EINVAL
21 // If we can block until Wait4 will succeed immediately, do so.
22 ready, err := p.blockUntilWaitable()
23 if err != nil {
24 return nil, err
26 if ready {
27 // Mark the process done now, before the call to Wait4,
28 // so that Process.signal will not send a signal.
29 p.setDone()
30 // Acquire a write lock on sigMu to wait for any
31 // active call to the signal method to complete.
32 p.sigMu.Lock()
33 p.sigMu.Unlock()
36 var status syscall.WaitStatus
37 var rusage syscall.Rusage
38 pid1, e := syscall.Wait4(p.Pid, &status, 0, &rusage)
39 if e != nil {
40 return nil, NewSyscallError("wait", e)
42 if pid1 != 0 {
43 p.setDone()
45 ps = &ProcessState{
46 pid: pid1,
47 status: status,
48 rusage: &rusage,
50 return ps, nil
53 var errFinished = errors.New("os: process already finished")
55 func (p *Process) signal(sig Signal) error {
56 if p.Pid == -1 {
57 return errors.New("os: process already released")
59 if p.Pid == 0 {
60 return errors.New("os: process not initialized")
62 p.sigMu.RLock()
63 defer p.sigMu.RUnlock()
64 if p.done() {
65 return errFinished
67 s, ok := sig.(syscall.Signal)
68 if !ok {
69 return errors.New("os: unsupported signal type")
71 if e := syscall.Kill(p.Pid, s); e != nil {
72 if e == syscall.ESRCH {
73 return errFinished
75 return e
77 return nil
80 func (p *Process) release() error {
81 // NOOP for unix.
82 p.Pid = -1
83 // no need for a finalizer anymore
84 runtime.SetFinalizer(p, nil)
85 return nil
88 func findProcess(pid int) (p *Process, err error) {
89 // NOOP for unix.
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