Skip to content

Commit a585107

Browse files
authored
Merge pull request #102 from superfly/expose-pid
Expose machine's PID
2 parents b2e8284 + 1458000 commit a585107

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

machine.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ func (m *Machine) Logger() *log.Entry {
163163
return m.logger.WithField("subsystem", userAgent)
164164
}
165165

166+
// PID returns the machine's running process PID or an error if not running
167+
func (m *Machine) PID() (int, error) {
168+
if m.cmd == nil || m.cmd.Process == nil {
169+
return 0, fmt.Errorf("machine is not running")
170+
}
171+
select {
172+
case <-m.exitCh:
173+
return 0, fmt.Errorf("machine process has exited")
174+
default:
175+
}
176+
return m.cmd.Process.Pid, nil
177+
}
178+
166179
// NetworkInterface represents a Firecracker microVM's network interface.
167180
type NetworkInterface struct {
168181
// MacAddress defines the MAC address that should be assigned to the network

0 commit comments

Comments
 (0)