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 // +build darwin freebsd linux netbsd openbsd windows | 5 // +build darwin freebsd linux netbsd openbsd windows |
6 | 6 |
7 package os | 7 package os |
8 | 8 |
9 import ( | 9 import ( |
10 "syscall" | 10 "syscall" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // since syscall one might have different field types across | 49 // since syscall one might have different field types across |
50 // different OS. | 50 // different OS. |
51 | 51 |
52 // Waitmsg stores the information about an exited process as reported by Wait. | 52 // Waitmsg stores the information about an exited process as reported by Wait. |
53 type Waitmsg struct { | 53 type Waitmsg struct { |
54 Pid int // The process's id. | 54 Pid int // The process's id. |
55 syscall.WaitStatus // System-dependent status info. | 55 syscall.WaitStatus // System-dependent status info. |
56 Rusage *syscall.Rusage // System-dependent resource usage in
fo. | 56 Rusage *syscall.Rusage // System-dependent resource usage in
fo. |
57 } | 57 } |
58 | 58 |
59 // Wait waits for process pid to exit or stop, and then returns a | |
60 // Waitmsg describing its status and an error, if any. | |
61 // Wait is equivalent to calling FindProcess and then Wait | |
62 // and Release on the result. | |
63 func Wait(pid int) (w *Waitmsg, err error) { | |
64 p, e := FindProcess(pid) | |
65 if e != nil { | |
66 return nil, e | |
67 } | |
68 defer p.Release() | |
69 return p.Wait() | |
70 } | |
71 | |
72 // Convert i to decimal string. | 59 // Convert i to decimal string. |
73 func itod(i int) string { | 60 func itod(i int) string { |
74 if i == 0 { | 61 if i == 0 { |
75 return "0" | 62 return "0" |
76 } | 63 } |
77 | 64 |
78 u := uint64(i) | 65 u := uint64(i) |
79 if i < 0 { | 66 if i < 0 { |
80 u = -u | 67 u = -u |
81 } | 68 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 res += " (trap " + itod(w.TrapCause()) + ")" | 100 res += " (trap " + itod(w.TrapCause()) + ")" |
114 } | 101 } |
115 case w.Continued(): | 102 case w.Continued(): |
116 res = "continued" | 103 res = "continued" |
117 } | 104 } |
118 if w.CoreDump() { | 105 if w.CoreDump() { |
119 res += " (core dumped)" | 106 res += " (core dumped)" |
120 } | 107 } |
121 return res | 108 return res |
122 } | 109 } |
LEFT | RIGHT |