Skip to content

Commit 9d715e8

Browse files
authored
Add NSpid to proc status (#557)
* Add NSpid to proc status Signed-off-by: Nir Levy <[email protected]> * Support NSpid with 2 pids Signed-off-by: Nir Levy <[email protected]> * Support list of nspids Signed-off-by: Nir Levy <[email protected]> --------- Signed-off-by: Nir Levy <[email protected]>
1 parent 8676d3d commit 9d715e8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

proc_status.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type ProcStatus struct {
3232

3333
// Thread group ID.
3434
TGID int
35+
// List of Pid namespace.
36+
NSpids []uint64
3537

3638
// Peak virtual memory size.
3739
VmPeak uint64 // nolint:revive
@@ -127,6 +129,8 @@ func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintByt
127129
copy(s.UIDs[:], strings.Split(vString, "\t"))
128130
case "Gid":
129131
copy(s.GIDs[:], strings.Split(vString, "\t"))
132+
case "NSpid":
133+
s.NSpids = calcNSPidsList(vString)
130134
case "VmPeak":
131135
s.VmPeak = vUintBytes
132136
case "VmSize":
@@ -200,3 +204,18 @@ func calcCpusAllowedList(cpuString string) []uint64 {
200204
sort.Slice(g, func(i, j int) bool { return g[i] < g[j] })
201205
return g
202206
}
207+
208+
func calcNSPidsList(nspidsString string) []uint64 {
209+
s := strings.Split(nspidsString, " ")
210+
var nspids []uint64
211+
212+
for _, nspid := range s {
213+
nspid, _ := strconv.ParseUint(nspid, 10, 64)
214+
if nspid == 0 {
215+
continue
216+
}
217+
nspids = append(nspids, nspid)
218+
}
219+
220+
return nspids
221+
}

proc_status_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestProcStatus(t *testing.T) {
3636
}{
3737
{name: "Pid", want: 26231, have: s.PID},
3838
{name: "Tgid", want: 26231, have: s.TGID},
39+
{name: "NSpid", want: 1, have: int(s.NSpids[0])},
3940
{name: "VmPeak", want: 58472 * 1024, have: int(s.VmPeak)},
4041
{name: "VmSize", want: 58440 * 1024, have: int(s.VmSize)},
4142
{name: "VmLck", want: 0 * 1024, have: int(s.VmLck)},

0 commit comments

Comments
 (0)