From 5f72125f9519cb4ca837e053dce9107ad53094e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Jabes?= Date: Wed, 19 Aug 2020 15:57:50 -0300 Subject: [PATCH 1/3] Add method to return service pid --- service.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/service.go b/service.go index 784ccd8..80d994b 100644 --- a/service.go +++ b/service.go @@ -164,6 +164,11 @@ func (s Service) FrameBuffer() *FrameBuffer { return s.xvfb } +//PID returns the service pid +func (s Service) PID() int { + return s.cmd.Process.Pid +} + // NewSeleniumService starts a Selenium instance in the background. func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Service, error) { s, err := newService(exec.Command("java"), "/wd/hub", port, opts...) From d4bf8bb48339ace8dae665a5cc695f0e9f79e2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Jabes?= Date: Wed, 19 Aug 2020 15:59:53 -0300 Subject: [PATCH 2/3] Add check for existing proccess before returning pid --- service.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/service.go b/service.go index 80d994b..5d13954 100644 --- a/service.go +++ b/service.go @@ -166,7 +166,11 @@ func (s Service) FrameBuffer() *FrameBuffer { //PID returns the service pid func (s Service) PID() int { - return s.cmd.Process.Pid + if s.cmd != nil { + return s.cmd.Process.Pid + } + + return 0 } // NewSeleniumService starts a Selenium instance in the background. From db35d55ecdb03709f9c766a9d83875e092f9b3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Jabes?= Date: Sat, 27 Mar 2021 17:01:56 -0300 Subject: [PATCH 3/3] fix(pid): change invalid pid value --- service.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/service.go b/service.go index 5d13954..6c4ab72 100644 --- a/service.go +++ b/service.go @@ -15,6 +15,8 @@ import ( "time" ) +const InvalidPid = -1 + // ServiceOption configures a Service instance. type ServiceOption func(*Service) error @@ -170,7 +172,7 @@ func (s Service) PID() int { return s.cmd.Process.Pid } - return 0 + return InvalidPid } // NewSeleniumService starts a Selenium instance in the background.