From 22c1d37b7a541c9ae5e4e9b841dacceccbb20785 Mon Sep 17 00:00:00 2001 From: Sudhabindu Das Date: Sat, 1 May 2021 22:09:16 +0530 Subject: [PATCH 1/3] (WIP )adding pgrp and sid --- process.go | 6 ++++++ process_darwin.go | 10 ++++++++++ process_freebsd.go | 8 ++++++++ process_unix.go | 4 ++++ process_windows.go | 10 ++++++++++ 5 files changed, 38 insertions(+) diff --git a/process.go b/process.go index 2b5e8ed..987134b 100644 --- a/process.go +++ b/process.go @@ -16,6 +16,12 @@ type Process interface { // PPid is the parent process ID for this process. PPid() int + // Pgid is the process group ID of the process + Pgrp() int + + // Sid is the session ID of the process + Sid() int + // Executable name running this process. This is not a path to the // executable. Executable() string diff --git a/process_darwin.go b/process_darwin.go index 5ee87fb..d7192f1 100644 --- a/process_darwin.go +++ b/process_darwin.go @@ -12,6 +12,8 @@ import ( type DarwinProcess struct { pid int ppid int + pgrp int + sid int binary string } @@ -23,6 +25,14 @@ func (p *DarwinProcess) PPid() int { return p.ppid } +func (p *DarwinProcess) Pgrp() int { + return p.pgrp +} + +func (p *DarwinProcess) Sid() int { + return p.sid +} + func (p *DarwinProcess) Executable() string { return p.binary } diff --git a/process_freebsd.go b/process_freebsd.go index 130acbe..3fd712c 100644 --- a/process_freebsd.go +++ b/process_freebsd.go @@ -121,6 +121,14 @@ func (p *UnixProcess) PPid() int { return p.ppid } +func (p *UnixProcess) Pgrp() int { + return p.pgrp +} + +func (p *UnixProcess) Sid() int { + return p.sid +} + func (p *UnixProcess) Executable() string { return p.binary } diff --git a/process_unix.go b/process_unix.go index cd217a8..7f62ecd 100644 --- a/process_unix.go +++ b/process_unix.go @@ -29,6 +29,10 @@ func (p *UnixProcess) PPid() int { return p.ppid } +func (p *UnixProcess) Pgrp() int { + return p.pgrp +} + func (p *UnixProcess) Executable() string { return p.binary } diff --git a/process_windows.go b/process_windows.go index f151974..99c58ab 100644 --- a/process_windows.go +++ b/process_windows.go @@ -42,6 +42,8 @@ type PROCESSENTRY32 struct { type WindowsProcess struct { pid int ppid int + pgrp int + sid int exe string } @@ -53,6 +55,14 @@ func (p *WindowsProcess) PPid() int { return p.ppid } +func (p *WindowsProcess) Pgrp() int { + return p.pgrp +} + +func (p *WindowsProcess) Sid() { + return p.sid +} + func (p *WindowsProcess) Executable() string { return p.exe } From 4b0890f769e5238a4fe83ad5ee64a839f6b5f026 Mon Sep 17 00:00:00 2001 From: Sudhabindu Das Date: Sat, 1 May 2021 22:13:02 +0530 Subject: [PATCH 2/3] added Sid to unix_process --- process_unix.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/process_unix.go b/process_unix.go index 7f62ecd..7e16c21 100644 --- a/process_unix.go +++ b/process_unix.go @@ -33,6 +33,10 @@ func (p *UnixProcess) Pgrp() int { return p.pgrp } +func (p *UnixProcess) Sid() int { + return p.sid +} + func (p *UnixProcess) Executable() string { return p.binary } From 81116e4c8a66d617f21d3b1536dd35f0c8b48727 Mon Sep 17 00:00:00 2001 From: Sudhabindu Das Date: Sat, 1 May 2021 22:43:57 +0530 Subject: [PATCH 3/3] (temp) using syscall to get pgid and sid --- process.go | 2 +- process_darwin.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/process.go b/process.go index 987134b..57e1b8b 100644 --- a/process.go +++ b/process.go @@ -16,7 +16,7 @@ type Process interface { // PPid is the parent process ID for this process. PPid() int - // Pgid is the process group ID of the process + // Pgrp is the process group ID of the process Pgrp() int // Sid is the session ID of the process diff --git a/process_darwin.go b/process_darwin.go index d7192f1..8ce55ea 100644 --- a/process_darwin.go +++ b/process_darwin.go @@ -73,9 +73,13 @@ func processes() ([]Process, error) { darwinProcs := make([]Process, len(procs)) for i, p := range procs { + pgid, _ := syscall.Getpgid(int(p.Pid)) + sid, _ := syscall.Getsid(int(p.Pid)) darwinProcs[i] = &DarwinProcess{ pid: int(p.Pid), ppid: int(p.PPid), + pgrp: pgid, + sid: sid, binary: darwinCstring(p.Comm), } }