|
|
|
@ -9,7 +9,6 @@ import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"math"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
@ -136,7 +135,7 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
|
|
|
|
|
// see https://github.com/shirou/gopsutil/issues/596#issuecomment-432707831 for implementation details
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
statPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "stat")
|
|
|
|
|
contents, err := ioutil.ReadFile(statPath)
|
|
|
|
|
contents, err := os.ReadFile(statPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
@ -391,7 +390,7 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
|
|
|
|
|
smapsPath = smapsRollupPath
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
contents, err := ioutil.ReadFile(smapsPath)
|
|
|
|
|
contents, err := os.ReadFile(smapsPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -484,7 +483,7 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
|
|
|
|
|
func (p *Process) EnvironWithContext(ctx context.Context) ([]string, error) {
|
|
|
|
|
environPath := common.HostProcWithContext(ctx, strconv.Itoa(int(p.Pid)), "environ")
|
|
|
|
|
|
|
|
|
|
environContent, err := ioutil.ReadFile(environPath)
|
|
|
|
|
environContent, err := os.ReadFile(environPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -668,7 +667,7 @@ func (p *Process) fillFromExeWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
cmdPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "cmdline")
|
|
|
|
|
cmdline, err := ioutil.ReadFile(cmdPath)
|
|
|
|
|
cmdline, err := os.ReadFile(cmdPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
@ -682,7 +681,7 @@ func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error
|
|
|
|
|
func (p *Process) fillSliceFromCmdlineWithContext(ctx context.Context) ([]string, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
cmdPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "cmdline")
|
|
|
|
|
cmdline, err := ioutil.ReadFile(cmdPath)
|
|
|
|
|
cmdline, err := os.ReadFile(cmdPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -705,7 +704,7 @@ func (p *Process) fillSliceFromCmdlineWithContext(ctx context.Context) ([]string
|
|
|
|
|
func (p *Process) fillFromIOWithContext(ctx context.Context) (*IOCountersStat, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
ioPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "io")
|
|
|
|
|
ioline, err := ioutil.ReadFile(ioPath)
|
|
|
|
|
ioline, err := os.ReadFile(ioPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -741,7 +740,7 @@ func (p *Process) fillFromIOWithContext(ctx context.Context) (*IOCountersStat, e
|
|
|
|
|
func (p *Process) fillFromStatmWithContext(ctx context.Context) (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
memPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "statm")
|
|
|
|
|
contents, err := ioutil.ReadFile(memPath)
|
|
|
|
|
contents, err := os.ReadFile(memPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, nil, err
|
|
|
|
|
}
|
|
|
|
@ -802,7 +801,7 @@ func (p *Process) fillNameWithContext(ctx context.Context) error {
|
|
|
|
|
func (p *Process) fillFromCommWithContext(ctx context.Context) error {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
statPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "comm")
|
|
|
|
|
contents, err := ioutil.ReadFile(statPath)
|
|
|
|
|
contents, err := os.ReadFile(statPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -819,7 +818,7 @@ func (p *Process) fillFromStatus() error {
|
|
|
|
|
func (p *Process) fillFromStatusWithContext(ctx context.Context) error {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
statPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "status")
|
|
|
|
|
contents, err := ioutil.ReadFile(statPath)
|
|
|
|
|
contents, err := os.ReadFile(statPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -1026,7 +1025,7 @@ func (p *Process) fillFromTIDStatWithContext(ctx context.Context, tid int32) (ui
|
|
|
|
|
statPath = common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "task", strconv.Itoa(int(tid)), "stat")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contents, err := ioutil.ReadFile(statPath)
|
|
|
|
|
contents, err := os.ReadFile(statPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, 0, nil, 0, 0, 0, nil, err
|
|
|
|
|
}
|
|
|
|
|