Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[process] implement ParentWithContext using PpidWithContext #1235

Merged
merged 2 commits into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,15 @@ func (p *Process) Parent() (*Process, error) {
return p.ParentWithContext(context.Background())
}

// ParentWithContext returns parent Process of the process.
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
ppid, err := p.PpidWithContext(ctx)
if err != nil {
return nil, err
}
return NewProcessWithContext(ctx, ppid)
}

// Status returns the process status.
// Return value could be one of these.
// R: Running S: Sleep T: Stop I: Idle
Expand Down
9 changes: 0 additions & 9 deletions process/process_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,6 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
return k.Proc.P_starttime.Sec*1000 + int64(k.Proc.P_starttime.Usec)/1000, nil
}

func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
ppid, err := p.PpidWithContext(ctx)
if err != nil {
return nil, err
}

return NewProcessWithContext(ctx, ppid)
}

func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) {
r, err := callPsWithContext(ctx, "state", p.Pid, false, false)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions process/process_fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
return "", common.ErrNotImplementedError
}

func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
return nil, common.ErrNotImplementedError
}

func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) {
return []string{""}, common.ErrNotImplementedError
}
Expand Down
4 changes: 0 additions & 4 deletions process/process_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
return k.Start.Sec*1000 + k.Start.Usec/1000, nil
}

func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
return nil, common.ErrNotImplementedError
}

func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) {
k, err := p.getKProc()
if err != nil {
Expand Down
11 changes: 0 additions & 11 deletions process/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,6 @@ func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
return p.fillFromCwdWithContext()
}

func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
err := p.fillFromStatusWithContext()
if err != nil {
return nil, err
}
if p.parent == 0 {
return nil, fmt.Errorf("wrong number of parents")
}
return NewProcessWithContext(ctx, p.parent)
}

func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) {
err := p.fillFromStatusWithContext()
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions process/process_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
return 0, common.ErrNotImplementedError
}

func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
return nil, common.ErrNotImplementedError
}

func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) {
k, err := p.getKProc()
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions process/process_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
return "", common.ErrNotImplementedError
}

func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
return nil, common.ErrNotImplementedError
}

func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) {
return []string{""}, common.ErrNotImplementedError
}
Expand Down
4 changes: 0 additions & 4 deletions process/process_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
return p.fillFromPathCwdWithContext(ctx)
}

func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
return nil, common.ErrNotImplementedError
}

func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) {
return []string{""}, common.ErrNotImplementedError
}
Expand Down
9 changes: 0 additions & 9 deletions process/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,6 @@ func (p *Process) CwdWithContext(_ context.Context) (string, error) {
return "", nil
}

func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
ppid, err := p.PpidWithContext(ctx)
if err != nil {
return nil, fmt.Errorf("could not get ParentProcessID: %s", err)
}

return NewProcessWithContext(ctx, ppid)
}

func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) {
return []string{""}, common.ErrNotImplementedError
}
Expand Down