Skip to content

Commit 9d658b3

Browse files
authored
RSDK-9566: Expose process id for managed processes. (#397)
1 parent 37789a9 commit 9d658b3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pexec/managed_process.go

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ type ManagedProcess interface {
3535
// Status return nil when the process is both alive and owned.
3636
// If err is non-nil, process may be a) alive but not owned or b) dead.
3737
Status() error
38+
39+
// UnixPid returns the pid of the process. This method returns an error if the pid is
40+
// unknown. For example, if the process hasn't been `Start`ed yet. Or if not on a unix system.
41+
UnixPid() (int, error)
3842
}
3943

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

114+
func (p *managedProcess) UnixPid() (int, error) {
115+
if p.cmd == nil || p.cmd.Process == nil {
116+
return 0, errors.New("Process not started")
117+
}
118+
return p.cmd.Process.Pid, nil
119+
}
120+
110121
func (p *managedProcess) Status() error {
111122
p.mu.Lock()
112123
defer p.mu.Unlock()

pexec/managed_process_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -695,3 +695,10 @@ func (fp *fakeProcess) Status() error {
695695
}
696696
return nil
697697
}
698+
699+
func (fp *fakeProcess) UnixPid() (int, error) {
700+
return 0, errors.New(`the NewManagedProcess API needlessly returns an interface
701+
instead of the structure itself. Thus tests depend on the returned interface. When
702+
in reality tests should just depend on the methods they rely on. UnixPid is not one
703+
of those methods (for better or worse)`)
704+
}

0 commit comments

Comments
 (0)