src/pkg/os/doc.go - The Go Programming Language

Golang

Source file src/pkg/os/doc.go

     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 returns 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	func (p *ProcessState) SysUsage() interface{} {
    83		return p.sysUsage()
    84	}
    85	
    86	// Hostname returns the host name reported by the kernel.
    87	func Hostname() (name string, err error) {
    88		return hostname()
    89	}
    90	
    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
    94	// further FileInfos.
    95	//
    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.
    99	//
   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) {
   107		return f.readdir(n)
   108	}
   109	
   110	// Readdirnames reads and returns a slice of names from the directory f.
   111	//
   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.
   115	//
   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
   121	// a non-nil error.
   122	func (f *File) Readdirnames(n int) (names []string, err error) {
   123		return f.readdirnames(n)
   124	}