Skip to content

Commit ad80414

Browse files
authored
Merge pull request #1 from sudhabindu1/add-pgrp
Add pgrp and sid for processes mitchellh#54
2 parents fca0296 + 81116e4 commit ad80414

5 files changed

+46
-0
lines changed

process.go

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ type Process interface {
1616
// PPid is the parent process ID for this process.
1717
PPid() int
1818

19+
// Pgrp is the process group ID of the process
20+
Pgrp() int
21+
22+
// Sid is the session ID of the process
23+
Sid() int
24+
1925
// Executable name running this process. This is not a path to the
2026
// executable.
2127
Executable() string

process_darwin.go

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
type DarwinProcess struct {
1313
pid int
1414
ppid int
15+
pgrp int
16+
sid int
1517
binary string
1618
}
1719

@@ -23,6 +25,14 @@ func (p *DarwinProcess) PPid() int {
2325
return p.ppid
2426
}
2527

28+
func (p *DarwinProcess) Pgrp() int {
29+
return p.pgrp
30+
}
31+
32+
func (p *DarwinProcess) Sid() int {
33+
return p.sid
34+
}
35+
2636
func (p *DarwinProcess) Executable() string {
2737
return p.binary
2838
}
@@ -63,9 +73,13 @@ func processes() ([]Process, error) {
6373

6474
darwinProcs := make([]Process, len(procs))
6575
for i, p := range procs {
76+
pgid, _ := syscall.Getpgid(int(p.Pid))
77+
sid, _ := syscall.Getsid(int(p.Pid))
6678
darwinProcs[i] = &DarwinProcess{
6779
pid: int(p.Pid),
6880
ppid: int(p.PPid),
81+
pgrp: pgid,
82+
sid: sid,
6983
binary: darwinCstring(p.Comm),
7084
}
7185
}

process_freebsd.go

+8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ func (p *UnixProcess) PPid() int {
121121
return p.ppid
122122
}
123123

124+
func (p *UnixProcess) Pgrp() int {
125+
return p.pgrp
126+
}
127+
128+
func (p *UnixProcess) Sid() int {
129+
return p.sid
130+
}
131+
124132
func (p *UnixProcess) Executable() string {
125133
return p.binary
126134
}

process_unix.go

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func (p *UnixProcess) PPid() int {
2929
return p.ppid
3030
}
3131

32+
func (p *UnixProcess) Pgrp() int {
33+
return p.pgrp
34+
}
35+
36+
func (p *UnixProcess) Sid() int {
37+
return p.sid
38+
}
39+
3240
func (p *UnixProcess) Executable() string {
3341
return p.binary
3442
}

process_windows.go

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ type PROCESSENTRY32 struct {
4242
type WindowsProcess struct {
4343
pid int
4444
ppid int
45+
pgrp int
46+
sid int
4547
exe string
4648
}
4749

@@ -53,6 +55,14 @@ func (p *WindowsProcess) PPid() int {
5355
return p.ppid
5456
}
5557

58+
func (p *WindowsProcess) Pgrp() int {
59+
return p.pgrp
60+
}
61+
62+
func (p *WindowsProcess) Sid() {
63+
return p.sid
64+
}
65+
5666
func (p *WindowsProcess) Executable() string {
5767
return p.exe
5868
}

0 commit comments

Comments
 (0)