OSDN Git Service

Update to current version of Go library (revision 94d654be2064).
[pf3gnuchains/gcc-fork.git] / libgo / go / os / exec_unix.go
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.
4
5 package os
6
7 import (
8         "runtime"
9         "syscall"
10 )
11
12 // Options for Wait.
13 const (
14         WNOHANG   = syscall.WNOHANG   // Don't wait if no process has exited.
15         WSTOPPED  = syscall.WSTOPPED  // If set, status of stopped subprocesses is also reported.
16         WUNTRACED = syscall.WUNTRACED // Usually an alias for WSTOPPED.
17         WRUSAGE   = 1 << 20           // Record resource usage.
18 )
19
20 // WRUSAGE must not be too high a bit, to avoid clashing with Linux's
21 // WCLONE, WALL, and WNOTHREAD flags, which sit in the top few bits of
22 // the options
23
24 // Wait waits for the Process to exit or stop, and then returns a
25 // Waitmsg describing its status and an Error, if any. The options
26 // (WNOHANG etc.) affect the behavior of the Wait call.
27 func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
28         if p.Pid == -1 {
29                 return nil, EINVAL
30         }
31         var status syscall.WaitStatus
32         var rusage *syscall.Rusage
33         if options&WRUSAGE != 0 {
34                 rusage = new(syscall.Rusage)
35                 options ^= WRUSAGE
36         }
37         pid1, e := syscall.Wait4(p.Pid, &status, options, rusage)
38         if e != 0 {
39                 return nil, NewSyscallError("wait", e)
40         }
41         w = new(Waitmsg)
42         w.Pid = pid1
43         w.WaitStatus = status
44         w.Rusage = rusage
45         return w, nil
46 }
47
48 // Release releases any resources associated with the Process.
49 func (p *Process) Release() Error {
50         // NOOP for unix.
51         p.Pid = -1
52         // no need for a finalizer anymore
53         runtime.SetFinalizer(p, nil)
54         return nil
55 }
56
57 // FindProcess looks for a running process by its pid.
58 // The Process it returns can be used to obtain information
59 // about the underlying operating system process.
60 func FindProcess(pid int) (p *Process, err Error) {
61         // NOOP for unix.
62         return newProcess(pid, 0), nil
63 }