|
|
@ -16,6 +16,7 @@ import (
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
invoke common.Invoker = common.Invoke{}
|
|
|
|
invoke common.Invoker = common.Invoke{}
|
|
|
|
ErrorNoChildren = errors.New("process does not have children")
|
|
|
|
ErrorNoChildren = errors.New("process does not have children")
|
|
|
|
|
|
|
|
ErrorProcessNotRunning = errors.New("process does not exist")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type Process struct {
|
|
|
|
type Process struct {
|
|
|
@ -136,6 +137,23 @@ func (p NumCtxSwitchesStat) String() string {
|
|
|
|
return string(s)
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NewProcess creates a new Process instance, it only stores the pid and
|
|
|
|
|
|
|
|
// checks that the process exists. Other method on Process can be used
|
|
|
|
|
|
|
|
// to get more information about the process. An error will be returned
|
|
|
|
|
|
|
|
// if the process does not exist.
|
|
|
|
|
|
|
|
func NewProcess(pid int32) (*Process, error) {
|
|
|
|
|
|
|
|
p := &Process{Pid: pid}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exists, err := PidExists(pid)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return p, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !exists {
|
|
|
|
|
|
|
|
return p, ErrorProcessNotRunning
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return p, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func PidExists(pid int32) (bool, error) {
|
|
|
|
func PidExists(pid int32) (bool, error) {
|
|
|
|
return PidExistsWithContext(context.Background(), pid)
|
|
|
|
return PidExistsWithContext(context.Background(), pid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|