OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [os/] [exec_unix.go] - Blame information for rev 760

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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.
4
 
5
// +build darwin freebsd linux netbsd openbsd
6
 
7
package os
8
 
9
import (
10
        "errors"
11
        "runtime"
12
        "syscall"
13
)
14
 
15
// Options for Wait.
16
const (
17
        WNOHANG   = syscall.WNOHANG   // Don't wait if no process has exited.
18
        WSTOPPED  = syscall.WSTOPPED  // If set, status of stopped subprocesses is also reported.
19
        WUNTRACED = syscall.WUNTRACED // Usually an alias for WSTOPPED.
20
        WRUSAGE   = 1 << 20           // Record resource usage.
21
)
22
 
23
// WRUSAGE must not be too high a bit, to avoid clashing with Linux's
24
// WCLONE, WALL, and WNOTHREAD flags, which sit in the top few bits of
25
// the options
26
 
27
// Wait waits for the Process to exit or stop, and then returns a
28
// Waitmsg describing its status and an error, if any. The options
29
// (WNOHANG etc.) affect the behavior of the Wait call.
30
func (p *Process) Wait(options int) (w *Waitmsg, err error) {
31
        if p.Pid == -1 {
32
                return nil, EINVAL
33
        }
34
        var status syscall.WaitStatus
35
        var rusage *syscall.Rusage
36
        if options&WRUSAGE != 0 {
37
                rusage = new(syscall.Rusage)
38
                options ^= WRUSAGE
39
        }
40
        pid1, e := syscall.Wait4(p.Pid, &status, options, rusage)
41
        if e != nil {
42
                return nil, NewSyscallError("wait", e)
43
        }
44
        // With WNOHANG pid is 0 if child has not exited.
45
        if pid1 != 0 && options&WSTOPPED == 0 {
46
                p.done = true
47
        }
48
        w = new(Waitmsg)
49
        w.Pid = pid1
50
        w.WaitStatus = status
51
        w.Rusage = rusage
52
        return w, nil
53
}
54
 
55
// Signal sends a signal to the Process.
56
func (p *Process) Signal(sig Signal) error {
57
        if p.done {
58
                return errors.New("os: process already finished")
59
        }
60
        if e := syscall.Kill(p.Pid, int(sig.(UnixSignal))); e != nil {
61
                return e
62
        }
63
        return nil
64
}
65
 
66
// Release releases any resources associated with the Process.
67
func (p *Process) Release() error {
68
        // NOOP for unix.
69
        p.Pid = -1
70
        // no need for a finalizer anymore
71
        runtime.SetFinalizer(p, nil)
72
        return nil
73
}
74
 
75
func findProcess(pid int) (p *Process, err error) {
76
        // NOOP for unix.
77
        return newProcess(pid, 0), nil
78
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.