mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-12 19:29:30 +08:00
Fix process.Foreground for BSDs, add openbsd implementation
This commit is contained in:
parent
878e0a701b
commit
8ef9b01052
@ -251,7 +251,7 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
out, err := invoke.CommandWithContext(ctx, ps, "-o", "stat=", "-p", string(pid))
|
out, err := invoke.CommandWithContext(ctx, ps, "-o", "stat=", "-p", strconv.Itoa(int(pid)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
out, err := invoke.CommandWithContext(ctx, ps, "-o", "stat=", "-p", string(pid))
|
out, err := invoke.CommandWithContext(ctx, ps, "-o", "stat=", "-p", strconv.Itoa(int(pid)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -162,6 +162,23 @@ func (p *Process) StatusWithContext(ctx context.Context) (string, error) {
|
|||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
func (p *Process) Foreground() (bool, error) {
|
||||||
|
return p.ForegroundWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
ps, err := exec.LookPath("ps")
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
out, err := invoke.CommandWithContext(ctx, ps, "-o", "stat=", "-p", strconv.Itoa(int(pid)))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return strings.IndexByte(string(out), '+') != -1, nil
|
||||||
|
}
|
||||||
func (p *Process) Uids() ([]int32, error) {
|
func (p *Process) Uids() ([]int32, error) {
|
||||||
return p.UidsWithContext(context.Background())
|
return p.UidsWithContext(context.Background())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user