3 ms·
I've been bitten by and tried to work around this as well. From what I can tell, the best you can really do is to parse by matching up parens, but someone could
by mort96 4y ago
I've been bitten by and tried to work around this as well. From what I can tell, the best you can really do is to parse by matching up parens, but someone could totally make a program with braces in its name. If I make a binary called "foo) R 10 20 30", the /proc/<pid>/stat entry will contain "1715376 (foo) R 10 20 30) 1544883 1715376 1544883...". It's terribly non-obvious how to deal with correctly.
- st_goliath 4y ago> It's terribly non-obvious how to deal with correctly. Like the post says: read the whole thing into memory and do a reverse search for the last ')', i.e. strrchr Once you are aware of the problem, it's obvious how to solve it, but I do agree that the hidden danger here is not immediately obvious at first.
- zokier 4y agoNote that man page says that the name is truncated to 16 chars, so if for whatever reason you don't want to do unbounded length read then you can use that
- jyxent 4y agoThey actually allow up to 64 characters in the kernel: https://github.com/torvalds/linux/blob/8395ae05cb5a2e31d36106e8c85efa11cda849be/fs/proc/array.c#L100 https://github.com/torvalds/linux/blob/8395ae05cb5a2e31d3610... This might just be for certain kernel things though. I don't see any regular processes that aren't truncated, but I see a bunch of kernel things that have more than 16 chars on my system.
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]