Skip to contentSkip to conversation

How can I parse the command name from /proc/<pid>/stat?

DISCUSSION Steven Stewart-Gallus 2 participants 3 messages Dec 4, 2014 – Dec 6, 2014

lore
Share & tools
lore
#0 lore raw

Hello,

Given an evil hacker trying to confuse process monitors that might use such strange process names as 'pause) R 0 0 (foo' how can I correctly parse the command name from /proc/<pid>/stat? Maybe I should just use /proc/<pid>/status? Maybe there should be some documentation written on the issue? I just wanted to send an email off to check if I was missing anything before writing a few small additions to the documentation or filing a bug report. procps-ng seems to use an ugly hack that involves knowing the limits on the size of a possible command name that I'm not actually sure works totally correctly.

Thank you,
Steven Stewart-Gallus

#1 lore raw
Quoted 10 lines · Steven Stewart-Gallus

Hello,

Given an evil hacker trying to confuse process monitors that might use such strange process names as 'pause) R 0 0 (foo' how can I correctly parse the command name from /proc/<pid>/stat? Maybe I should just use /proc/<pid>/status? Maybe there should be some documentation written on the issue? I just wanted to send an email off to check if I was missing anything before writing a few small additions to the documentation or filing a bug report. procps-ng seems to use an ugly hack that involves knowing the limits on the size of a possible command name that I'm not actually sure works totally correctly.

You can do something like :

cmd_start = strchr(stat_buf, '(');
cmd_end = strrchr(stat_buf, ')');

Cheers
Suzuki

Quoted 10 lines

Thank you,
Steven Stewart-Gallus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw

Thank you, I dislike the idea of relying upon stat never gaining any other part that uses ) but that would work instead of using status.