Overview

Package os provides a platform-independent interface to operating system
functionality. The design is Unix-like, although the error handling is Go-like;
failing calls return values of type error rather than error numbers. Often, more
information is available within the error. For example, if a call that takes a
file name fails, such as Open or Stat, the error will include the failing file
name when printed and will be of type *PathError, which may be unpacked for more
information.

The os interface is intended to be uniform across all operating systems.
Features not generally available appear in the system-specific package syscall.

Here is a simple example, opening a file and reading some of it.

If the open fails, the error string will be self-explanatory, like

  1. open file.go: no such file or directory

The file’s data can then be read into a slice of bytes. Read and Write take
their byte counts from the length of the argument slice.

  1. data := make([]byte, 100)
  2. count, err := file.Read(data)
  3. if err != nil {
  4. log.Fatal(err)
  5. }
  6. fmt.Printf("read %d bytes: %q\n", count, data[:count])

Index

Package files

dir_unix.go error.go error_unix.go exec_posix.go executable.go file.go file_unix.go path.go pipe_linux.go stat.go stat_unix.go str.go sys_linux.go types.go wait_waitid.go

Constants

  1. const (
  2. // Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified.
  3. O_RDONLY = syscall. // open the file read-only.
  4. O_WRONLY int = .O_WRONLY // open the file write-only.
  5. O_RDWR = syscall. // open the file read-write.
  6. // The remaining values may be or'ed in to control behavior.
  7. O_APPEND int = .O_APPEND // append data to the file when writing.
  8. O_CREATE = syscall. // create a new file if none exists.
  9. O_EXCL int = .O_EXCL // used with O_CREATE, file must not exist.
  10. O_SYNC = syscall. // open for synchronous I/O.
  11. )

Flags to OpenFile wrapping those of the underlying system. Not all flags may be
implemented on a given system.

  1. const (
  2. SEEK_SET int = 0 // seek relative to the origin of the file
  3. SEEK_CUR = 1 // seek relative to the current offset
  4. SEEK_END int = 2 // seek relative to the end
  5. )

Seek whence values.

Deprecated: Use io.SeekStart, io.SeekCurrent, and io.SeekEnd.

  1. const (
  2. PathSeparator = '/' // OS-specific path separator
  3. PathListSeparator = ':' // OS-specific path list separator
  4. )
  1. const DevNull = "/dev/null"

DevNull is the name of the operating system’s ``null device.’’ On Unix-like
systems, it is “/dev/null”; on Windows, “NUL”.

Variables

  1. var (
  2. ErrInvalid = .New("invalid argument") // methods on File will return this error when the receiver is nil
  3. ErrPermission = .New("permission denied")
  4. ErrExist = .New("file already exists")
  5. ErrNotExist = .New("file does not exist")
  6. ErrClosed = .New("file already closed")
  7. ErrNoDeadline = .ErrNoDeadline
  8. )

Portable analogs of some common system call errors.

  1. var (
  2. Stdin = (uintptr(.Stdin), "/dev/stdin")
  3. Stdout = (uintptr(.Stdout), "/dev/stdout")
  4. Stderr = (uintptr(.Stderr), "/dev/stderr")
  5. )

Stdin, Stdout, and Stderr are open Files pointing to the standard input,
standard output, and standard error file descriptors.

Note that the Go runtime writes to standard error for panics and crashes;
closing Stderr may cause those messages to go elsewhere, perhaps to a file
opened later.

  1. var Args []

Args hold the command-line arguments, starting with the program name.

func Chdir

  1. func Chdir(dir string)

Chdir changes the current working directory to the named directory. If there is
an error, it will be of type *PathError.

func Chmod

  1. func Chmod(name string, mode ) error

Chmod changes the mode of the named file to mode. If the file is a symbolic
link, it changes the mode of the link’s target. If there is an error, it will be
of type *PathError.

A different subset of the mode bits are used, depending on the operating system.

On Unix, the mode’s permission bits, ModeSetuid, ModeSetgid, and ModeSticky are
used.

On Windows, the mode must be non-zero but otherwise only the 0200 bit (owner
writable) of mode is used; it controls whether the file’s read-only attribute is
set or cleared. attribute. The other bits are currently unused. Use mode 0400
for a read-only file and 0600 for a readable+writable file.

On Plan 9, the mode’s permission bits, ModeAppend, ModeExclusive, and
ModeTemporary are used.


Example:

  1. if err := os.Chmod("some-filename", 0644); err != nil {
  2. log.Fatal(err)
  3. }

func Chown

  1. func Chown(name string, uid, gid ) error

Chown changes the numeric uid and gid of the named file. If the file is a
symbolic link, it changes the uid and gid of the link’s target. If there is an
error, it will be of type *PathError.

On Windows, it always returns the syscall.EWINDOWS error, wrapped in *PathError.

func

  1. func Chtimes(name , atime time., mtime time.) error

Chtimes changes the access and modification times of the named file, similar to
the Unix utime() or utimes() functions.

The underlying filesystem may truncate or round the values to a less precise
time unit. If there is an error, it will be of type *PathError.


Example:

  1. mtime := time.Date(2006, time.February, 1, 3, 4, 5, 0, time.UTC)
  2. atime := time.Date(2007, time.March, 2, 4, 5, 6, 0, time.UTC)
  3. if err := os.Chtimes("some-filename", atime, mtime); err != nil {
  4. log.Fatal(err)
  5. }

func Clearenv

  1. func Clearenv()

Clearenv deletes all environment variables.

func Environ

  1. func Environ() []string

Environ returns a copy of strings representing the environment, in the form
“key=value”.

func

  1. func Executable() (, error)

Executable returns the path name for the executable that started the current
process. There is no guarantee that the path is still pointing to the correct
executable. If a symlink was used to start the process, depending on the
operating system, the result might be the symlink or the path it pointed to. If
a stable result is needed, path/filepath.EvalSymlinks might help.

Executable returns an absolute path unless an error occurred.

The main use case is finding resources located relative to an executable.

Executable is not supported on nacl.

func

  1. func Exit(code )

Exit causes the current program to exit with the given status code.
Conventionally, code zero indicates success, non-zero an error. The program
terminates immediately; deferred functions are not run.

func Expand

  1. func Expand(s string, mapping func() string)

Expand replaces ${var} or $var in the string based on the mapping function. For
example, os.ExpandEnv(s) is equivalent to os.Expand(s, os.Getenv).

func ExpandEnv

  1. func ExpandEnv(s string)

ExpandEnv replaces ${var} or $var in the string according to the values of the
current environment variables. References to undefined variables are replaced by
the empty string.


Example:

  1. fmt.Println(os.ExpandEnv("$USER lives in ${HOME}."))
  2. // Output:
  3. // gopher lives in /usr/gopher.

func

  1. func Getegid()

Getegid returns the numeric effective group id of the caller.

On Windows, it returns -1.

func Getenv

  1. func Getenv(key string)

Getenv retrieves the value of the environment variable named by the key. It
returns the value, which will be empty if the variable is not present. To
distinguish between an empty value and an unset value, use LookupEnv.


Example:

  1. fmt.Printf("%s lives in %s.\n", os.Getenv("USER"), os.Getenv("HOME"))
  2. // Output:
  3. // gopher lives in /usr/gopher.

func

  1. func Geteuid()

Geteuid returns the numeric effective user id of the caller.

On Windows, it returns -1.

func Getgid

  1. func Getgid() int

Getgid returns the numeric group id of the caller.

On Windows, it returns -1.

  1. func Getgroups() ([], error)

Getgroups returns a list of the numeric ids of groups that the caller belongs
to.

On Windows, it returns syscall.EWINDOWS. See the os/user package for a possible
alternative.

func

  1. func Getpagesize()

Getpagesize returns the underlying system’s memory page size.

func Getpid

  1. func Getpid() int

Getpid returns the process id of the caller.

func

  1. func Getppid()

Getppid returns the process id of the caller’s parent.

func Getuid

  1. func Getuid() int

Getuid returns the numeric user id of the caller.

On Windows, it returns -1.

func

  1. func Getwd() (dir , err error)

Getwd returns a rooted path name corresponding to the current directory. If the
current directory can be reached via multiple paths (due to symbolic links),
Getwd may return any one of them.

func

  1. func Hostname() (name , err error)

Hostname returns the host name reported by the kernel.

func

  1. func IsExist(err ) bool

IsExist returns a boolean indicating whether the error is known to report that a
file or directory already exists. It is satisfied by ErrExist as well as some
syscall errors.

func

  1. func IsNotExist(err ) bool

IsNotExist returns a boolean indicating whether the error is known to report
that a file or directory does not exist. It is satisfied by ErrNotExist as well
as some syscall errors.


Example:

  1. filename := "a-nonexistent-file"
  2. if _, err := os.Stat(filename); os.IsNotExist(err) {
  3. }
  4. // Output:
  5. // file does not exist

func IsPathSeparator

  1. func IsPathSeparator(c uint8)

IsPathSeparator reports whether c is a directory separator character.

func IsPermission

  1. func IsPermission(err error)

IsPermission returns a boolean indicating whether the error is known to report
that permission is denied. It is satisfied by ErrPermission as well as some
syscall errors.

func IsTimeout

  1. func IsTimeout(err error)

IsTimeout returns a boolean indicating whether the error is known to report that
a timeout occurred.

func Lchown

Lchown changes the numeric uid and gid of the named file. If the file is a
symbolic link, it changes the uid and gid of the link itself. If there is an
error, it will be of type *PathError.

On Windows, it always returns the syscall.EWINDOWS error, wrapped in *PathError.

  1. func Link(oldname, newname string)

Link creates newname as a hard link to the oldname file. If there is an error,
it will be of type *LinkError.

func LookupEnv

  1. func LookupEnv(key string) (, bool)

LookupEnv retrieves the value of the environment variable named by the key. If
the variable is present in the environment the value (which may be empty) is
returned and the boolean is true. Otherwise the returned value will be empty and
the boolean will be false.


Example:

  1. show := func(key string) {
  2. val, ok := os.LookupEnv(key)
  3. if !ok {
  4. fmt.Printf("%s not set\n", key)
  5. } else {
  6. fmt.Printf("%s=%s\n", key, val)
  7. }
  8. }
  9. show("USER")
  10. show("GOPATH")
  11. // Output:
  12. // USER=gopher
  13. // GOPATH not set

func Mkdir

  1. func Mkdir(name string, perm ) error

Mkdir creates a new directory with the specified name and permission bits
(before umask). If there is an error, it will be of type *PathError.

func

  1. func MkdirAll(path , perm FileMode)

MkdirAll creates a directory named path, along with any necessary parents, and
returns nil, or else returns an error. The permission bits perm (before umask)
are used for all directories that MkdirAll creates. If path is already a
directory, MkdirAll does nothing and returns nil.

func NewSyscallError

  1. func NewSyscallError(syscall string, err ) error

NewSyscallError returns, as an error, a new SyscallError with the given system
call name and error details. As a convenience, if err is nil, NewSyscallError
returns nil.

  1. func Readlink(name ) (string, )

Readlink returns the destination of the named symbolic link. If there is an
error, it will be of type *PathError.

  1. func Remove(name string)

Remove removes the named file or directory. If there is an error, it will be of
type *PathError.

func RemoveAll

  1. func RemoveAll(path string)

RemoveAll removes path and any children it contains. It removes everything it
can but returns the first error it encounters. If the path does not exist,
RemoveAll returns nil (no error).

func Rename

  1. func Rename(oldpath, newpath string)

Rename renames (moves) oldpath to newpath. If newpath already exists and is not
a directory, Rename replaces it. OS-specific restrictions may apply when oldpath
and newpath are in different directories. If there is an error, it will be of
type *LinkError.

func SameFile

  1. func SameFile(fi1, fi2 FileInfo)

SameFile reports whether fi1 and fi2 describe the same file. For example, on
Unix this means that the device and inode fields of the two underlying
structures are identical; on other systems the decision may be based on the path
names. SameFile only applies to results returned by this package’s Stat. It
returns false in other cases.

func Setenv

  1. func Setenv(key, value string)

Setenv sets the value of the environment variable named by the key. It returns
an error, if any.

  1. func Symlink(oldname, newname string)

Symlink creates newname as a symbolic link to oldname. If there is an error, it
will be of type *LinkError.

func TempDir

  1. func TempDir() string

TempDir returns the default directory to use for temporary files.

On Unix systems, it returns $TMPDIR if non-empty, else /tmp. On Windows, it uses
GetTempPath, returning the first non-empty value from %TMP%, %TEMP%,
%USERPROFILE%, or the Windows directory. On Plan 9, it returns /tmp.

The directory is neither guaranteed to exist nor have accessible permissions.

func

  1. func Truncate(name , size int64)

Truncate changes the size of the named file. If the file is a symbolic link, it
changes the size of the link’s target. If there is an error, it will be of type
*PathError.

func Unsetenv

  1. func Unsetenv(key string)

Unsetenv unsets a single environment variable.


Example:

  1. os.Setenv("TMPDIR", "/my/tmp")
  2. defer os.Unsetenv("TMPDIR")

type

  1. type File struct {
  2. // contains filtered or unexported fields
  3. }

File represents an open file descriptor.

func

  1. func Create(name ) (*File, )

Create creates the named file with mode 0666 (before umask), truncating it if it
already exists. If successful, methods on the returned File can be used for I/O;
the associated file descriptor has mode O_RDWR. If there is an error, it will be
of type *PathError.

func NewFile

  1. func NewFile(fd uintptr, name ) *File

NewFile returns a new File with the given file descriptor and name. The returned
value will be nil if fd is not a valid file descriptor.

func

  1. func Open(name ) (*File, )

Open opens the named file for reading. If successful, methods on the returned
file can be used for reading; the associated file descriptor has mode O_RDONLY.
If there is an error, it will be of type *PathError.

func OpenFile

  1. func OpenFile(name string, flag , perm FileMode) (*, error)

OpenFile is the generalized open call; most users will use Open or Create
instead. It opens the named file with specified flag (O_RDONLY etc.) and perm
(before umask), if applicable. If successful, methods on the returned File can
be used for I/O. If there is an error, it will be of type *PathError.


Example:

  1. f, err := os.OpenFile("notes.txt", os.O_RDWR|os.O_CREATE, 0755)
  2. if err != nil {
  3. log.Fatal(err)
  4. }
  5. if err := f.Close(); err != nil {
  6. }


Example:

  1. // If the file doesn't exist, create it, or append to the file
  2. f, err := os.OpenFile("access.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
  3. if err != nil {
  4. log.Fatal(err)
  5. }
  6. if _, err := f.Write([]byte("appended some data\n")); err != nil {
  7. log.Fatal(err)
  8. }
  9. if err := f.Close(); err != nil {
  10. log.Fatal(err)
  11. }

func

  1. func Pipe() (r *, w *File, err )

Pipe returns a connected pair of Files; reads from r return bytes written to w.
It returns the files and an error, if any.

func (*File) Chdir

  1. func (f *File) Chdir()

Chdir changes the current working directory to the file, which must be a
directory. If there is an error, it will be of type *PathError.

func (*File) Chmod

  1. func (f *File) Chmod(mode ) error

Chmod changes the mode of the file to mode. If there is an error, it will be of
type *PathError.

func (*File)

  1. func (f *) Chown(uid, gid int)

Chown changes the numeric uid and gid of the named file. If there is an error,
it will be of type *PathError.

On Windows, it always returns the syscall.EWINDOWS error, wrapped in *PathError.

func (*File) Close

  1. func (f *File) Close()

Close closes the File, rendering it unusable for I/O. It returns an error, if
any.

func (*File) Fd

  1. func (f *File) Fd()

Fd returns the integer Unix file descriptor referencing the open file. The file
descriptor is valid only until f.Close is called or f is garbage collected. On
Unix systems this will cause the SetDeadline methods to stop working.

func (*File) Name

    Name returns the name of the file as presented to Open.

    func (*File) Read

    1. func (f *File) Read(b []) (n int, err )

    Read reads up to len(b) bytes from the File. It returns the number of bytes read
    and any error encountered. At end of file, Read returns 0, io.EOF.

    func (*File) ReadAt

    1. func (f *File) ReadAt(b [], off int64) (n , err error)

    ReadAt reads len(b) bytes from the File starting at byte offset off. It returns
    the number of bytes read and the error, if any. ReadAt always returns a non-nil
    error when n < len(b). At end of file, that error is io.EOF.

    func (*File)

    1. func (f *) Readdir(n int) ([], error)

    Readdir reads the contents of the directory associated with file and returns a
    slice of up to n FileInfo values, as would be returned 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 (*File)

    1. func (f *) Readdirnames(n int) (names [], err error)

    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.

    1. func (f *) Seek(offset int64, whence ) (ret int64, err )

    Seek sets the offset for the next Read or Write on file to offset, interpreted
    according to whence: 0 means relative to the origin of the file, 1 means
    relative to the current offset, and 2 means relative to the end. It returns the
    new offset and an error, if any. The behavior of Seek on a file opened with
    O_APPEND is not specified.

    func (*File) SetDeadline

    1. func (f *File) SetDeadline(t .Time)

    SetDeadline sets the read and write deadlines for a File. It is equivalent to
    calling both SetReadDeadline and SetWriteDeadline.

    Only some kinds of files support setting a deadline. Calls to SetDeadline for
    files that do not support deadlines will return ErrNoDeadline. On most systems
    ordinary files do not support deadlines, but pipes do.

    A deadline is an absolute time after which I/O operations fail with an error
    instead of blocking. The deadline applies to all future and pending I/O, not
    just the immediately following call to Read or Write. After a deadline has been
    exceeded, the connection can be refreshed by setting a deadline in the future.

    An error returned after a timeout fails will implement the Timeout method, and
    calling the Timeout method will return true. The PathError and SyscallError
    types implement the Timeout method. In general, call IsTimeout to test whether
    an error indicates a timeout.

    An idle timeout can be implemented by repeatedly extending the deadline after
    successful Read or Write calls.

    A zero value for t means I/O operations will not time out.

    func (*File) SetReadDeadline

    1. func (f *File) SetReadDeadline(t .Time)

    SetReadDeadline sets the deadline for future Read calls and any
    currently-blocked Read call. A zero value for t means Read will not time out.
    Not all files support setting deadlines; see SetDeadline.

    func (*File) SetWriteDeadline

    1. func (f *File) SetWriteDeadline(t .Time)

    SetWriteDeadline sets the deadline for any future Write calls and any
    currently-blocked Write call. Even if Write times out, it may return n > 0,
    indicating that some of the data was successfully written. A zero value for t
    means Write will not time out. Not all files support setting deadlines; see
    SetDeadline.

    func (*File) Stat

    1. func (f *File) Stat() (, error)

    func (*File)

    Sync commits the current contents of the file to stable storage. Typically, this
    means flushing the file system’s in-memory copy of recently written data to
    disk.

    func (*File)

    1. func (f *) Truncate(size int64)

    Truncate changes the size of the file. It does not change the I/O offset. If
    there is an error, it will be of type *PathError.

    func (*File) Write

    1. func (f *File) Write(b []) (n int, err )

    Write writes len(b) bytes to the File. It returns the number of bytes written
    and an error, if any. Write returns a non-nil error when n != len(b).

    func (*File) WriteAt

    1. func (f *File) WriteAt(b [], off int64) (n , err error)

    WriteAt writes len(b) bytes to the File starting at byte offset off. It returns
    the number of bytes written and an error, if any. WriteAt returns a non-nil
    error when n != len(b).

    func (*File)

    1. func (f *) WriteString(s string) (n , err error)

    WriteString is like Write, but writes the contents of string s rather than a
    slice of bytes.

    type

    1. type FileInfo interface {
    2. Name() // base name of the file
    3. Size() int64 // length in bytes for regular files; system-dependent for others
    4. Mode() // file mode bits
    5. ModTime() time. // modification time
    6. IsDir() bool // abbreviation for Mode().IsDir()
    7. Sys() interface{} // underlying data source (can return nil)
    8. }

    A FileInfo describes a file and is returned by Stat and Lstat.

    func

    1. func Lstat(name ) (FileInfo, )

    Lstat returns a FileInfo describing the named file. If the file is a symbolic
    link, the returned FileInfo describes the symbolic link. Lstat makes no attempt
    to follow the link. If there is an error, it will be of type *PathError.

    func Stat

    1. func Stat(name string) (, error)

    Stat returns a FileInfo describing the named file. If there is an error, it will
    be of type *PathError.

    type

    1. type FileMode

    A FileMode represents a file’s mode and permission bits. The bits have the same
    definition on all systems, so that information about files can be moved from one
    system to another portably. Not all bits apply to all systems. The only required
    bit is ModeDir for directories.

    1. const (
    2. // The single letters are the abbreviations
    3. // used by the String method's formatting.
    4. ModeDir FileMode = 1 << (32 - 1 - ) // d: is a directory
    5. ModeAppend // a: append-only
    6. ModeExclusive // l: exclusive use
    7. ModeTemporary // T: temporary file; Plan 9 only
    8. ModeSymlink // L: symbolic link
    9. ModeDevice // D: device file
    10. ModeNamedPipe // p: named pipe (FIFO)
    11. ModeSocket // S: Unix domain socket
    12. ModeSetuid // u: setuid
    13. ModeSetgid // g: setgid
    14. ModeCharDevice // c: Unix character device, when ModeDevice is set
    15. ModeSticky // t: sticky
    16.  
    17. // Mask for the type bits. For regular files, none will be set.
    18. ModeType = ModeDir | | ModeNamedPipe | | ModeDevice
    19.  
    20. ModePerm = 0777 // Unix permission bits
    21. )

    The defined file mode bits are the most significant bits of the FileMode. The
    nine least-significant bits are the standard Unix rwxrwxrwx permissions. The
    values of these bits should be considered part of the public API and may be used
    in wire protocols or disk representations: they must not be changed, although
    new bits might be added.


    Example:

    1. fi, err := os.Lstat("some-filename")
    2. if err != nil {
    3. log.Fatal(err)
    4. }
    5. switch mode := fi.Mode(); {
    6. case mode.IsRegular():
    7. fmt.Println("regular file")
    8. case mode.IsDir():
    9. fmt.Println("directory")
    10. case mode&os.ModeSymlink != 0:
    11. fmt.Println("symbolic link")
    12. case mode&os.ModeNamedPipe != 0:
    13. }

    func (FileMode)

    1. func (m ) IsDir() bool

    IsDir reports whether m describes a directory. That is, it tests for the ModeDir
    bit being set in m.

    func (FileMode)

    1. func (m ) IsRegular() bool

    IsRegular reports whether m describes a regular file. That is, it tests that no
    mode type bits are set.

    func (FileMode)

    1. func (m ) Perm() FileMode

    Perm returns the Unix permission bits in m.

    func (FileMode)

    1. func (m ) String() string

    type

    1. type LinkError struct {
    2. Op
    3. Old string
    4. New
    5. Err error
    6. }

    LinkError records an error during a link or symlink or rename system call and
    the paths that caused it.

    func (*LinkError)

    1. func (e *) Error() string

    type

    1. type PathError struct {
    2. Op
    3. Path string
    4. Err
    5. }

    PathError records an error and the operation and file path that caused it.

    1. func (e *PathError) Error()

    func (*PathError) Timeout

    1. func (e *PathError) Timeout()

    Timeout reports whether this error represents a timeout.

    type ProcAttr

    1. type ProcAttr struct {
    2. // If Dir is non-empty, the child changes into the directory before
    3. // creating the process.
    4. Dir string
    5. // If Env is non-nil, it gives the environment variables for the
    6. // new process in the form returned by Environ.
    7. // If it is nil, the result of Environ will be used.
    8. Env []
    9. // Files specifies the open files inherited by the new process. The
    10. // first three entries correspond to standard input, standard output, and
    11. // standard error. An implementation may support additional entries,
    12. // depending on the underlying operating system. A nil entry corresponds
    13. // to that file being closed when the process starts.
    14. Files []*File
    15.  
    16. // Operating system-specific process creation attributes.
    17. // Note that setting this field means that your program
    18. // may not execute properly or even compile on some
    19. // operating systems.
    20. Sys *.SysProcAttr
    21. }

    ProcAttr holds the attributes that will be applied to a new process started by
    StartProcess.

    type

    1. type Process struct {
    2. Pid
    3. // contains filtered or unexported fields
    4. }

    Process stores the information about a process created by StartProcess.

    func FindProcess

    1. func FindProcess(pid int) (*, error)

    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.

    On Unix systems, FindProcess always succeeds and returns a Process for the given
    pid, regardless of whether the process exists.

    func

    1. func StartProcess(name , argv []string, attr *) (*Process, )

    StartProcess starts a new process with the program, arguments and attributes
    specified by name, argv and attr. The argv slice will become os.Args in the new
    process, so it normally starts with the program name.

    If the calling goroutine has locked the operating system thread with
    runtime.LockOSThread and modified any inheritable OS-level thread state (for
    example, Linux or Plan 9 name spaces), the new process will inherit the caller’s
    thread state.

    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 (*Process) Kill

    1. func (p *Process) Kill()

    Kill causes the Process to exit immediately.

    func (*Process) Release

    1. func (p *Process) Release()

    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 (*Process) Signal

    1. func (p *Process) Signal(sig ) error

    Signal sends a signal to the Process. Sending Interrupt on Windows is not
    implemented.

    func (*Process)

    1. func (p *) Wait() (*ProcessState, )

    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. On most operating systems, the Process must be a child of the current
    process or an error will be returned.

    type ProcessState

    1. type ProcessState struct {
    2. // contains filtered or unexported fields
    3. }

    ProcessState stores information about a process, as reported by Wait.

    func (*ProcessState) Exited

    1. func (p *ProcessState) Exited()

    Exited reports whether the program has exited.

    func (*ProcessState) Pid

    1. func (p *ProcessState) Pid()

    Pid returns the process id of the exited process.

    func (*ProcessState) String

    1. func (p *ProcessState) String()

    func (*ProcessState) Success

    1. func (p *ProcessState) Success()

    Success reports whether the program exited successfully, such as with exit
    status 0 on Unix.

    func (*ProcessState) Sys

    1. func (p *ProcessState) Sys() interface{}

    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 (*ProcessState)

    1. func (p *) SysUsage() interface{}

    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. (On Unix,
    syscall.Rusage matches struct rusage
    as defined in the getrusage(2) manual page.)

    func (*ProcessState) SystemTime

    1. func (p *ProcessState) SystemTime() .Duration

    SystemTime returns the system CPU time of the exited process and its children.

    func (*ProcessState)

    1. func (p *) UserTime() time.

    UserTime returns the user CPU time of the exited process and its children.

    type Signal

    1. type Signal interface {
    2. String() string
    3. Signal() // to distinguish from other Stringers
    4. }

    A Signal represents an operating system signal. The usual underlying
    implementation is operating system-dependent: on Unix it is syscall.Signal.

    1. var (
    2. Interrupt = syscall.
    3. Kill Signal = .SIGKILL
    4. )

    The only signal values guaranteed to be present in the os package on all systems
    are Interrupt (send the process an interrupt) and Kill (force the process to
    exit). Interrupt is not implemented on Windows; using it with os.Process.Signal
    will return an error.

    type

    1. type SyscallError struct {
    2. Syscall
    3. Err error
    4. }

    SyscallError records an error from a specific system call.

    func (*SyscallError)

    1. func (e *) Error() string