oss-sec mailing list archives
Re: [patch] proc.5: tell how to parse /proc/*/stat correctly
From: Jakub Wilk <jwilk () jwilk net>
Date: Fri, 30 Dec 2022 21:15:54 +0100
* Tavis Ormandy <taviso () gmail com>, 2022-12-28 01:50:
But, really, I just don't see how this can practically be said to be parsable...In its current form it never will be. The solution is to place this variable-length field last. Then you can "cut -d ' ' -f 51-" to get the command+args part (assuming I counted all those fields correctly ...)Of course, this breaks backwards compatability.I think that cut command doesn't handle newlines,
Indeed.
There already is 'ps -q $$ -o >comm='
FWIW, "ps ... -o comm=" doesn't just print the raw comm value: it replaces non-printable chars with punctuation characters, and it may append " <defunct>" if the process is a zombie.
The easiest way to get unmangled comm is to read it from /proc/$PID/comm, then strip the trailing newline.
(But I suspect most /proc/*/stat parsers don't care about the comm field at all; they just want to skip over it to get their hands on the following fields.)
-- Jakub Wilk
Current thread:
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly, (continued)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Theodore Ts'o (Dec 29)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Demi Marie Obenour (Dec 29)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Alan Coopersmith (Dec 29)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Steffen Nurpmeso (Dec 29)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly David A. Wheeler (Dec 29)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Jeffrey Walton (Dec 29)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Steffen Nurpmeso (Dec 29)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Steffen Nurpmeso (Dec 28)
- RE: [patch] proc.5: tell how to parse /proc/*/stat correctly David Laight (Dec 31)
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Solar Designer (Dec 31)
- Message not available
- Re: [patch] proc.5: tell how to parse /proc/*/stat correctly Jakub Wilk (Dec 30)