github.com/rohankumardubey/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/pkg/os/doc.go (about) 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. 4 5 package os 6 7 import "time" 8 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) 14 } 15 16 // StartProcess starts a new process with the program, arguments and attributes 17 // specified by name, argv and attr. 18 // 19 // StartProcess is a low-level interface. The os/exec package provides 20 // higher-level interfaces. 21 // 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) 25 } 26 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 { 31 return p.release() 32 } 33 34 // Kill causes the Process to exit immediately. 35 func (p *Process) Kill() error { 36 return p.kill() 37 } 38 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) { 43 return p.wait() 44 } 45 46 // Signal sends a signal to the Process. 47 func (p *Process) Signal(sig Signal) error { 48 return p.signal(sig) 49 } 50 51 // UserTime returns the user CPU time of the exited process and its children. 52 func (p *ProcessState) UserTime() time.Duration { 53 return p.userTime() 54 } 55 56 // SystemTime returns the system CPU time of the exited process and its children. 57 func (p *ProcessState) SystemTime() time.Duration { 58 return p.systemTime() 59 } 60 61 // Exited reports whether the program has exited. 62 func (p *ProcessState) Exited() bool { 63 return p.exited() 64 } 65 66 // Success reports whether the program exited successfully, 67 // such as with exit status 0 on Unix. 68 func (p *ProcessState) Success() bool { 69 return p.success() 70 } 71 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{} { 76 return p.sys() 77 } 78 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 // (On Unix, *syscall.Rusage matches struct rusage as defined in the 83 // getrusage(2) manual page.) 84 func (p *ProcessState) SysUsage() interface{} { 85 return p.sysUsage() 86 } 87 88 // Hostname returns the host name reported by the kernel. 89 func Hostname() (name string, err error) { 90 return hostname() 91 } 92 93 // Readdir reads the contents of the directory associated with file and 94 // returns a slice of up to n FileInfo values, as would be returned 95 // by Lstat, in directory order. Subsequent calls on the same file will yield 96 // further FileInfos. 97 // 98 // If n > 0, Readdir returns at most n FileInfo structures. In this case, if 99 // Readdir returns an empty slice, it will return a non-nil error 100 // explaining why. At the end of a directory, the error is io.EOF. 101 // 102 // If n <= 0, Readdir returns all the FileInfo from the directory in 103 // a single slice. In this case, if Readdir succeeds (reads all 104 // the way to the end of the directory), it returns the slice and a 105 // nil error. If it encounters an error before the end of the 106 // directory, Readdir returns the FileInfo read until that point 107 // and a non-nil error. 108 func (f *File) Readdir(n int) (fi []FileInfo, err error) { 109 if f == nil { 110 return nil, ErrInvalid 111 } 112 return f.readdir(n) 113 } 114 115 // Readdirnames reads and returns a slice of names from the directory f. 116 // 117 // If n > 0, Readdirnames returns at most n names. In this case, if 118 // Readdirnames returns an empty slice, it will return a non-nil error 119 // explaining why. At the end of a directory, the error is io.EOF. 120 // 121 // If n <= 0, Readdirnames returns all the names from the directory in 122 // a single slice. In this case, if Readdirnames succeeds (reads all 123 // the way to the end of the directory), it returns the slice and a 124 // nil error. If it encounters an error before the end of the 125 // directory, Readdirnames returns the names read until that point and 126 // a non-nil error. 127 func (f *File) Readdirnames(n int) (names []string, err error) { 128 if f == nil { 129 return nil, ErrInvalid 130 } 131 return f.readdirnames(n) 132 }