/proc/PID/stat can't be parsed when `comm` field contains spaces
See original GitHub issue$ cat a\ script.sh
#!/bin/bash
cut -d' ' -f1-4 /proc/$$/stat
python3 -m jc /proc/$$/stat
$ ./a\ script.sh
1377890 (a script.sh) S
jc: Error - oc parser could not parse the input data.
If this is the correct parser, try setting the locale to C (LC_ALL=C).
For details use the -d or -dd option. Use "jc -h --oc" for help.
It appears that only the comm
field can contain )
, so a correct parser would read the entire file and consider everything between the first (
and the last )
(including spaces and newlines) to be the command.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Invalid parsing of /proc/<pid>/stat · Issue #120 · dstat ... - GitHub
SUMMARY dstat assumes that the 2nd column in /proc/ /stat cannot contain whitespace, but it does in some cases.
Read more >what are the downsides of splitting /proc/pid/stat by whitespace?
The chief problem is that the space character ( 0x20 ) is used both for the delimiter between records and may also appear...
Read more >proc(5) - Linux manual page - man7.org
/proc/[pid]/comm (since Linux 2.6.33) This file exposes the process's comm value—that is, the command name associated with the process.
Read more >std::cin input with spaces? - c++ - Stack Overflow
It doesn't "fail"; it just stops reading. It sees a lexical token as a "string". Use std::getline : #include <string> #include <iostream> int...
Read more >Parsing copy/paste data with multiple spaces
My current approach is to parse the data after it's copy/pasted from the PDF. When I copy/paste I can structure the data into...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, I’m wrong. Sorry about that. I didn’t notice the
^
, and by default it matches the start of the string rather than the start of a line. So,LGTM
Ok, looks like I have this fixed in the
dev
branch. Basically just swapped to regex vs. simple split(). Had to update the signature match regex to allow for newlines as well. Tests are passing.https://github.com/kellyjonbrazil/jc/blob/dev/jc/parsers/proc_pid_stat.py
You can test this new parser by copying it to your
jc
plugin directory (https://github.com/kellyjonbrazil/jc/tree/dev#custom-parsers)Magic syntax won’t work this way, but you can
cat /proc/pid/$$/stat | jc --proc-pid-stat
to test. This is because I also updated the signature in the top-level Proc parser.For full testing of magic syntax and the normal
--proc
top-level parser you can clone thedev
branch and test.I’ll wait for some more fixes before pushing a new release with the fix.
Thanks again for your help!