diff --git a/net/net.go b/net/net.go index 4d120dc7..48660ec7 100644 --- a/net/net.go +++ b/net/net.go @@ -39,13 +39,14 @@ type Addr struct { } type ConnectionStat struct { - Fd uint32 `json:"fd"` - Family uint32 `json:"family"` - Type uint32 `json:"type"` - Laddr Addr `json:"localaddr"` - Raddr Addr `json:"remoteaddr"` - Status string `json:"status"` - Pid int32 `json:"pid"` + Fd uint32 `json:"fd"` + Family uint32 `json:"family"` + Type uint32 `json:"type"` + Laddr Addr `json:"localaddr"` + Raddr Addr `json:"remoteaddr"` + Status string `json:"status"` + Uids []int32 `json:"uids"` + Pid int32 `json:"pid"` } // System wide stats about different network protocols diff --git a/net/net_linux.go b/net/net_linux.go index 0803d8e7..c9c5d401 100644 --- a/net/net_linux.go +++ b/net/net_linux.go @@ -14,6 +14,7 @@ import ( "syscall" "github.com/shirou/gopsutil/internal/common" + "github.com/shirou/gopsutil/process" ) // NetIOCounters returnes network I/O statistics for every network @@ -281,6 +282,7 @@ type connTmp struct { laddr Addr raddr Addr status string + uids []int32 pid int32 boundPid int32 path string @@ -338,6 +340,7 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { Type: c.sockType, Laddr: c.laddr, Raddr: c.raddr, + Uids: c.uids, Status: c.status, Pid: c.pid, } @@ -346,6 +349,11 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { } else { conn.Pid = c.pid } + + // fetch process owner Real, effective, saved set, and filesystem UIDs + proc := process.Process{Pid: conn.Pid} + conn.Uids, _ = proc.Uids() + // check duplicate using JSON format json := conn.String() _, exists := dupCheckMap[json]