Skip to content

Commit 07f2b60

Browse files
authored
Get process comm from /proc/PID/status instead of /proc/PID/comm (#178)
Get process comm from /proc/PID/status instead of /proc/PID/comm, as it only exists since kernel 2.6.33.
1 parent 61dca1f commit 07f2b60

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

gprofiler/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def random_prefix() -> str:
487487

488488

489489
def process_comm(process: Process) -> str:
490-
comm = Path(f"/proc/{process.pid}/comm").read_text()
491-
# the kernel always adds \n
492-
assert comm.endswith('\n'), f"unexpected comm: {comm!r}"
493-
return comm[:-1]
490+
status = Path(f"/proc/{process.pid}/status").read_text()
491+
name_line = status.splitlines()[0]
492+
assert name_line.startswith("Name:\t")
493+
return name_line.split("\t", 1)[1]

0 commit comments

Comments
 (0)