MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / GetProcessInfoByPID

Method GetProcessInfoByPID

agent/app/service/process.go:98–195  ·  view source on GitHub ↗
(pid int32)

Source from the content-addressed store, hash-verified

96}
97
98func (ps *ProcessService) GetProcessInfoByPID(pid int32) (*websocket.PsProcessData, error) {
99 p, err := process.NewProcess(pid)
100 if err != nil {
101 return nil, fmt.Errorf("get process info by pid %v: %v", pid, err)
102 }
103
104 exists, err := p.IsRunning()
105 if err != nil || !exists {
106 return nil, fmt.Errorf("process %v is not running", pid)
107 }
108
109 data := &websocket.PsProcessData{
110 PID: pid,
111 }
112
113 if name, err := p.Name(); err == nil {
114 data.Name = name
115 }
116
117 if ppid, err := p.Ppid(); err == nil {
118 data.PPID = ppid
119 }
120
121 if username, err := p.Username(); err == nil {
122 data.Username = username
123 }
124
125 if status, err := p.Status(); err == nil {
126 if len(status) > 0 {
127 data.Status = status[0]
128 }
129 }
130
131 if createTime, err := p.CreateTime(); err == nil {
132 data.StartTime = time.Unix(createTime/1000, 0).Format("2006-01-02 15:04:05")
133 }
134
135 if numThreads, err := p.NumThreads(); err == nil {
136 data.NumThreads = numThreads
137 }
138
139 if connections, err := p.Connections(); err == nil {
140 data.NumConnections = len(connections)
141
142 var connects []websocket.ProcessConnect
143 for _, conn := range connections {
144 pc := websocket.ProcessConnect{
145 Status: conn.Status,
146 Laddr: conn.Laddr,
147 Raddr: conn.Raddr,
148 PID: pid,
149 Name: data.Name,
150 }
151 connects = append(connects, pc)
152 }
153 data.Connects = connects
154 }
155

Callers

nothing calls this directly

Calls 4

getMemoryDetailFunction · 0.85
NameMethod · 0.65
StatusMethod · 0.65
FormatMethod · 0.45

Tested by

no test coverage detected