cmd

package
v2.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2023 License: GPL-3.0, BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrProcessDone = errors.New("os: process already finished")

ErrProcessDone indicates a Process has finished.

Functions

func Getpid

func Getpid() int

Getpid returns the process id of the caller.

func Getppid

func Getppid() int

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

Types

type ProcAttr

type ProcAttr struct {
	// If Dir is non-empty, the child changes into the directory before
	// creating the process.
	Dir string
	// If Env is non-nil, it gives the environment variables for the
	// new process in the form returned by Environ.
	// If it is nil, the result of Environ will be used.
	Env []string
	// Files specifies the open files inherited by the new process. The
	// first three entries correspond to standard input, standard output, and
	// standard error. An implementation may support additional entries,
	// depending on the underlying operating system. A nil entry corresponds
	// to that file being closed when the process starts.
	Files []interface{}

	// Operating system-specific process creation attributes.
	// Note that setting this field means that your program
	// may not execute properly or even compile on some
	// operating systems.
	Sys *forkexec.SysProcAttr
}

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

type Process

type Process struct {
	Pid int
	// contains filtered or unexported fields
}

Process stores the information about a process created by StartProcess.

func FindProcess

func FindProcess(pid int) (*Process, 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 StartProcess

func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error)

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

func (p *Process) Kill() error

Kill causes the Process to exit immediately. Kill does not wait until the Process has actually exited. This only kills the Process itself, not any other processes it may have started.

func (*Process) Release

func (p *Process) Release() error

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

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

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

func (*Process) Wait

func (p *Process) Wait() (*ProcessState, error)

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

type ProcessState struct {
	// contains filtered or unexported fields
}

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

func (*ProcessState) ExitCode

func (p *ProcessState) ExitCode() int

ExitCode returns the exit code of the exited process, or -1 if the process hasn't exited or was terminated by a signal.

func (*ProcessState) Exited

func (p *ProcessState) Exited() bool

Exited reports whether the program has exited.

func (*ProcessState) Pid

func (p *ProcessState) Pid() int

Pid returns the process id of the exited process.

func (*ProcessState) String

func (p *ProcessState) String() string

func (*ProcessState) Success

func (p *ProcessState) Success() bool

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

func (*ProcessState) Sys

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) SysUsage

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

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

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

func (*ProcessState) UserTime

func (p *ProcessState) UserTime() time.Duration

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

type Signal

type Signal interface {
	String() string
	Signal() // to distinguish from other Stringers
}

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

var (
	Interrupt Signal = syscall.SIGINT
	Kill      Signal = syscall.SIGKILL
)

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL