Skip to content

Commit 300b80c

Browse files
authored
analyzer/linux: Fix get_proc_status parsing (#2769)
* analyzer/linux: Fix get_proc_status parsing When parsing the `/proc/<id>/status` file some field are empty which made the dict() conversion fail because the list length was 1. With this change, we are spliting on the ":" character and striping the key and the value so we can get the key without the ":" at the end and the value without any "\t" at the beginning or "\n" at the end. * analyzer/linux: convert parent process id (PPid) to int
1 parent a187ad6 commit 300b80c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

analyzer/linux/lib/api/process.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ def is_alive(self):
2525
status = self.get_proc_status()
2626
if not status:
2727
return False
28-
if "zombie" in status.get("State:", ""):
28+
if "zombie" in status.get("State", ""):
2929
return False
3030
return True
3131

3232
def get_parent_pid(self):
33-
return self.get_proc_status().get("PPid")
33+
return int(self.get_proc_status().get("PPid"))
3434

3535
def get_proc_status(self):
3636
try:
3737
with open(f"/proc/{self.pid}/status") as f:
3838
status = f.readlines()
39-
status_values = dict([j.strip().split(maxsplit=1) for j in status])
39+
status_values = dict([tuple(map(str.strip, j.split(':',1))) for j in status])
4040
return status_values
4141
except Exception:
4242
log.critical("Could not get process status for pid %s", self.pid)

0 commit comments

Comments
 (0)