Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package os | 5 package os |
6 | 6 |
7 import "syscall" | 7 import ( |
8 » "runtime" | |
9 » "syscall" | |
10 ) | |
8 | 11 |
9 // Options for Wait. | 12 // Options for Wait. |
10 const ( | 13 const ( |
11 WNOHANG = syscall.WNOHANG // Don't wait if no process has exited. | 14 WNOHANG = syscall.WNOHANG // Don't wait if no process has exited. |
12 WSTOPPED = syscall.WSTOPPED // If set, status of stopped subprocesses is also reported. | 15 WSTOPPED = syscall.WSTOPPED // If set, status of stopped subprocesses is also reported. |
13 WUNTRACED = syscall.WUNTRACED // Usually an alias for WSTOPPED. | 16 WUNTRACED = syscall.WUNTRACED // Usually an alias for WSTOPPED. |
14 WRUSAGE = 1 << 20 // Record resource usage. | 17 WRUSAGE = 1 << 20 // Record resource usage. |
15 ) | 18 ) |
16 | 19 |
17 // WRUSAGE must not be too high a bit, to avoid clashing with Linux's | 20 // WRUSAGE must not be too high a bit, to avoid clashing with Linux's |
18 // WCLONE, WALL, and WNOTHREAD flags, which sit in the top few bits of | 21 // WCLONE, WALL, and WNOTHREAD flags, which sit in the top few bits of |
19 // the options | 22 // the options |
20 | 23 |
21 // Wait waits for the Process to exit or stop, and then returns a | 24 // Wait waits for the Process to exit or stop, and then returns a |
22 // Waitmsg describing its status and an Error, if any. The options | 25 // Waitmsg describing its status and an Error, if any. The options |
23 // (WNOHANG etc.) affect the behavior of the Wait call. | 26 // (WNOHANG etc.) affect the behavior of the Wait call. |
24 func (p *Process) Wait(options int) (w *Waitmsg, err Error) { | 27 func (p *Process) Wait(options int) (w *Waitmsg, err Error) { |
28 if p.Pid == -1 { | |
29 return nil, EINVAL | |
30 } | |
25 var status syscall.WaitStatus | 31 var status syscall.WaitStatus |
26 var rusage *syscall.Rusage | 32 var rusage *syscall.Rusage |
27 if options&WRUSAGE != 0 { | 33 if options&WRUSAGE != 0 { |
28 rusage = new(syscall.Rusage) | 34 rusage = new(syscall.Rusage) |
29 options ^= WRUSAGE | 35 options ^= WRUSAGE |
30 } | 36 } |
31 pid1, e := syscall.Wait4(p.Pid, &status, options, rusage) | 37 pid1, e := syscall.Wait4(p.Pid, &status, options, rusage) |
32 if e != 0 { | 38 if e != 0 { |
33 return nil, NewSyscallError("wait", e) | 39 return nil, NewSyscallError("wait", e) |
34 } | 40 } |
35 w = new(Waitmsg) | 41 w = new(Waitmsg) |
36 w.Pid = pid1 | 42 w.Pid = pid1 |
37 w.WaitStatus = status | 43 w.WaitStatus = status |
38 w.Rusage = rusage | 44 w.Rusage = rusage |
39 return w, nil | 45 return w, nil |
40 } | 46 } |
41 | 47 |
42 // Close releases resources assosiated with the Process, | 48 // Release releases any resources associated with the Process. |
r
2011/02/02 05:28:23
s/assosiated/associated/
brainman
2011/02/02 06:50:35
Done.
| |
43 // rendering it unusable for waiting or quering. | 49 func (p *Process) Release() Error { |
r
2011/02/02 05:28:23
quering??
brainman
2011/02/02 06:50:35
Done.
| |
44 // It returns an Error, if any. | |
45 func (p *Process) Close() Error { | |
46 // NOOP for unix. | 50 // NOOP for unix. |
51 p.Pid = -1 | |
52 // no need for a finalizer anymore | |
53 runtime.SetFinalizer(p, nil) | |
47 return nil | 54 return nil |
48 } | 55 } |
49 | 56 |
50 // FundProcess looks for running process by its pid. It returns | 57 // FindProcess looks for a running process by its pid. |
r
2011/02/02 05:28:23
s/Fund/Find/
s/running/a &/
s/pid/process id, pid/
brainman
2011/02/02 06:50:35
Done.
| |
51 // Process that can be used to obtain information about process. | 58 // The Process it returns can be used to obtain information |
52 // It returns an Error, if any. | 59 // about the underlying operating system process. |
53 func FindProcess(pid int) (p *Process, err Error) { | 60 func FindProcess(pid int) (p *Process, err Error) { |
54 // NOOP for unix. | 61 // NOOP for unix. |
55 » return &Process{pid, 0}, nil | 62 » return newProcess(pid, 0), nil |
56 } | 63 } |
LEFT | RIGHT |