1 // Copyright 2012 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.
9 // FindProcess looks for a running process by its pid.
10 // The Process it returns can be used to obtain information
11 // about the underlying operating system process.
12 func FindProcess(pid
int) (p
*Process
, err error
) {
13 return findProcess(pid
)
16 // StartProcess starts a new process with the program, arguments and attributes
17 // specified by name, argv and attr.
19 // StartProcess is a low-level interface. The os/exec package provides
20 // higher-level interfaces.
22 // If there is an error, it will be of type *PathError.
23 func StartProcess(name
string, argv
[]string, attr
*ProcAttr
) (*Process
, error
) {
24 return startProcess(name
, argv
, attr
)
27 // Release releases any resources associated with the Process p,
28 // rendering it unusable in the future.
29 // Release only needs to be called if Wait is not.
30 func (p
*Process
) Release() error
{
34 // Kill causes the Process to exit immediately.
35 func (p
*Process
) Kill() error
{
39 // Wait waits for the Process to exit, and then returns a
40 // ProcessState describing its status and an error, if any.
41 // Wait releases any resources associated with the Process.
42 func (p
*Process
) Wait() (*ProcessState
, error
) {
46 // Signal sends a signal to the Process.
47 func (p
*Process
) Signal(sig Signal
) error
{
51 // UserTime returns the user CPU time of the exited process and its children.
52 func (p
*ProcessState
) UserTime() time
.Duration
{
56 // SystemTime returns the system CPU time of the exited process and its children.
57 func (p
*ProcessState
) SystemTime() time
.Duration
{
61 // Exited returns whether the program has exited.
62 func (p
*ProcessState
) Exited() bool {
66 // Success reports whether the program exited successfully,
67 // such as with exit status 0 on Unix.
68 func (p
*ProcessState
) Success() bool {
72 // Sys returns system-dependent exit information about
73 // the process. Convert it to the appropriate underlying
74 // type, such as syscall.WaitStatus on Unix, to access its contents.
75 func (p
*ProcessState
) Sys() interface{} {
79 // SysUsage returns system-dependent resource usage information about
80 // the exited process. Convert it to the appropriate underlying
81 // type, such as *syscall.Rusage on Unix, to access its contents.
82 func (p
*ProcessState
) SysUsage() interface{} {
86 // Hostname returns the host name reported by the kernel.
87 func Hostname() (name
string, err error
) {
91 // Readdir reads the contents of the directory associated with file and
92 // returns an array of up to n FileInfo values, as would be returned
93 // by Lstat, in directory order. Subsequent calls on the same file will yield
96 // If n > 0, Readdir returns at most n FileInfo structures. In this case, if
97 // Readdir returns an empty slice, it will return a non-nil error
98 // explaining why. At the end of a directory, the error is io.EOF.
100 // If n <= 0, Readdir returns all the FileInfo from the directory in
101 // a single slice. In this case, if Readdir succeeds (reads all
102 // the way to the end of the directory), it returns the slice and a
103 // nil error. If it encounters an error before the end of the
104 // directory, Readdir returns the FileInfo read until that point
105 // and a non-nil error.
106 func (f
*File
) Readdir(n
int) (fi
[]FileInfo
, err error
) {
110 // Readdirnames reads and returns a slice of names from the directory f.
112 // If n > 0, Readdirnames returns at most n names. In this case, if
113 // Readdirnames returns an empty slice, it will return a non-nil error
114 // explaining why. At the end of a directory, the error is io.EOF.
116 // If n <= 0, Readdirnames returns all the names from the directory in
117 // a single slice. In this case, if Readdirnames succeeds (reads all
118 // the way to the end of the directory), it returns the slice and a
119 // nil error. If it encounters an error before the end of the
120 // directory, Readdirnames returns the names read until that point and
122 func (f
*File
) Readdirnames(n
int) (names
[]string, err error
) {
123 return f
.readdirnames(n
)