2012-01-25 22:54:22 +01:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package os
|
|
|
|
|
2012-03-06 18:57:23 +01:00
|
|
|
import "time"
|
|
|
|
|
2012-01-25 22:54:22 +01:00
|
|
|
// FindProcess looks for a running process by its pid.
|
|
|
|
// The Process it returns can be used to obtain information
|
|
|
|
// about the underlying operating system process.
|
|
|
|
func FindProcess(pid int) (p *Process, err error) {
|
|
|
|
return findProcess(pid)
|
|
|
|
}
|
|
|
|
|
2012-03-06 18:57:23 +01:00
|
|
|
// StartProcess starts a new process with the program, arguments and attributes
|
|
|
|
// specified by name, argv and attr.
|
|
|
|
//
|
|
|
|
// StartProcess is a low-level interface. The os/exec package provides
|
|
|
|
// higher-level interfaces.
|
|
|
|
//
|
|
|
|
// If there is an error, it will be of type *PathError.
|
|
|
|
func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error) {
|
|
|
|
return startProcess(name, argv, attr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release releases any resources associated with the Process p,
|
|
|
|
// rendering it unusable in the future.
|
|
|
|
// Release only needs to be called if Wait is not.
|
|
|
|
func (p *Process) Release() error {
|
|
|
|
return p.release()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kill causes the Process to exit immediately.
|
|
|
|
func (p *Process) Kill() error {
|
|
|
|
return p.kill()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait waits for the Process to exit, and then returns a
|
|
|
|
// ProcessState describing its status and an error, if any.
|
|
|
|
// Wait releases any resources associated with the Process.
|
|
|
|
func (p *Process) Wait() (*ProcessState, error) {
|
|
|
|
return p.wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Signal sends a signal to the Process.
|
|
|
|
func (p *Process) Signal(sig Signal) error {
|
|
|
|
return p.signal(sig)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserTime returns the user CPU time of the exited process and its children.
|
|
|
|
func (p *ProcessState) UserTime() time.Duration {
|
|
|
|
return p.userTime()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SystemTime returns the system CPU time of the exited process and its children.
|
|
|
|
func (p *ProcessState) SystemTime() time.Duration {
|
|
|
|
return p.systemTime()
|
|
|
|
}
|
|
|
|
|
2013-11-06 20:49:01 +01:00
|
|
|
// Exited reports whether the program has exited.
|
2012-03-06 18:57:23 +01:00
|
|
|
func (p *ProcessState) Exited() bool {
|
|
|
|
return p.exited()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success reports whether the program exited successfully,
|
|
|
|
// such as with exit status 0 on Unix.
|
|
|
|
func (p *ProcessState) Success() bool {
|
|
|
|
return p.success()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sys returns system-dependent exit information about
|
|
|
|
// the process. Convert it to the appropriate underlying
|
|
|
|
// type, such as syscall.WaitStatus on Unix, to access its contents.
|
|
|
|
func (p *ProcessState) Sys() interface{} {
|
|
|
|
return p.sys()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SysUsage returns system-dependent resource usage information about
|
|
|
|
// the exited process. Convert it to the appropriate underlying
|
|
|
|
// type, such as *syscall.Rusage on Unix, to access its contents.
|
2013-07-16 08:54:42 +02:00
|
|
|
// (On Unix, *syscall.Rusage matches struct rusage as defined in the
|
|
|
|
// getrusage(2) manual page.)
|
2012-03-06 18:57:23 +01:00
|
|
|
func (p *ProcessState) SysUsage() interface{} {
|
|
|
|
return p.sysUsage()
|
|
|
|
}
|
|
|
|
|
2012-01-25 22:54:22 +01:00
|
|
|
// Hostname returns the host name reported by the kernel.
|
|
|
|
func Hostname() (name string, err error) {
|
|
|
|
return hostname()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Readdir reads the contents of the directory associated with file and
|
2012-11-21 08:03:38 +01:00
|
|
|
// returns a slice of up to n FileInfo values, as would be returned
|
2012-01-25 22:54:22 +01:00
|
|
|
// by Lstat, in directory order. Subsequent calls on the same file will yield
|
|
|
|
// further FileInfos.
|
|
|
|
//
|
|
|
|
// If n > 0, Readdir returns at most n FileInfo structures. In this case, if
|
|
|
|
// Readdir returns an empty slice, it will return a non-nil error
|
|
|
|
// explaining why. At the end of a directory, the error is io.EOF.
|
|
|
|
//
|
|
|
|
// If n <= 0, Readdir returns all the FileInfo from the directory in
|
|
|
|
// a single slice. In this case, if Readdir succeeds (reads all
|
|
|
|
// the way to the end of the directory), it returns the slice and a
|
|
|
|
// nil error. If it encounters an error before the end of the
|
|
|
|
// directory, Readdir returns the FileInfo read until that point
|
|
|
|
// and a non-nil error.
|
|
|
|
func (f *File) Readdir(n int) (fi []FileInfo, err error) {
|
2013-11-06 20:49:01 +01:00
|
|
|
if f == nil {
|
|
|
|
return nil, ErrInvalid
|
|
|
|
}
|
2012-01-25 22:54:22 +01:00
|
|
|
return f.readdir(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Readdirnames reads and returns a slice of names from the directory f.
|
|
|
|
//
|
|
|
|
// If n > 0, Readdirnames returns at most n names. In this case, if
|
|
|
|
// Readdirnames returns an empty slice, it will return a non-nil error
|
|
|
|
// explaining why. At the end of a directory, the error is io.EOF.
|
|
|
|
//
|
|
|
|
// If n <= 0, Readdirnames returns all the names from the directory in
|
|
|
|
// a single slice. In this case, if Readdirnames succeeds (reads all
|
|
|
|
// the way to the end of the directory), it returns the slice and a
|
|
|
|
// nil error. If it encounters an error before the end of the
|
|
|
|
// directory, Readdirnames returns the names read until that point and
|
|
|
|
// a non-nil error.
|
|
|
|
func (f *File) Readdirnames(n int) (names []string, err error) {
|
2013-11-06 20:49:01 +01:00
|
|
|
if f == nil {
|
|
|
|
return nil, ErrInvalid
|
|
|
|
}
|
2012-01-25 22:54:22 +01:00
|
|
|
return f.readdirnames(n)
|
|
|
|
}
|