Skip to content

Commit

Permalink
RSDK-9566: Expose process id for managed processes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgottlieb committed Dec 18, 2024
1 parent 37789a9 commit e114fb6
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit e114fb6

Please sign in to comment.