question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

/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:closed
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hvenevcommented, Sep 28, 2022

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

1reaction
kellyjonbrazilcommented, Sep 28, 2022

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 the dev branch and test.

I’ll wait for some more fixes before pushing a new release with the fix.

Thanks again for your help!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found