[PLUG] quick solution for parsing cmdline file

website reader website.reader3 at gmail.com
Tue Oct 9 03:51:35 UTC 2012


In regard to parsing the /proc/pid/cmdline, the best solution for me
was to open the file in "rb" or binary read-only mode and then to use
the getc() function and actually watch for the NULL character on the
fly and convert it to a space character while transferring the
characters one-by-one to a buffer.  Later on, I used the strstr
compare function to look for a particular substring in the converted
cmdline buffer.  This seems to work quite well, the pid_t pid# is
returned from the function call, if a match occurs, otherwise a -1 is
returned.



More information about the PLUG mailing list