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.
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.
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
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) {
31 var status syscall.WaitStatus
32 var rusage *syscall.Rusage
33 if options&WRUSAGE != 0 {
34 rusage = new(syscall.Rusage)
37 pid1, e := syscall.Wait4(p.Pid, &status, options, rusage)
39 return nil, NewSyscallError("wait", e)
48 // Release releases any resources associated with the Process.
49 func (p *Process) Release() Error {
52 // no need for a finalizer anymore
53 runtime.SetFinalizer(p, nil)
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) {
62 return newProcess(pid, 0), nil