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

RSDK-9566: Expose process id for managed processes. #397

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions pexec/managed_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type ManagedProcess interface {
// Status return nil when the process is both alive and owned.
// If err is non-nil, process may be a) alive but not owned or b) dead.
Status() error

// UnixPid returns the pid of the process. This method returns an error if the pid is
// unknown. For example, if the process hasn't been `Start`ed yet. Or if not on a unix system.
UnixPid() (int, error)
}

// NewManagedProcess returns a new, unstarted, from the given configuration.
Expand Down Expand Up @@ -107,6 +111,13 @@ func (p *managedProcess) ID() string {
return p.id
}

func (p *managedProcess) UnixPid() (int, error) {
if p.cmd == nil || p.cmd.Process == nil {
return 0, errors.New("Process not started")
}
return p.cmd.Process.Pid, nil
}

func (p *managedProcess) Status() error {
p.mu.Lock()
defer p.mu.Unlock()
Expand Down
Loading