title: Parsing /proc/maps?
body: <p>I wrote the following code in C. What I have done so far is open the proc directory and read the processes inside - dictories that did not consist of numerical characters were simply disregarded as I only want to look at the numeric directories. What I want to do is to print the PID of all the processes in the proc directory that have read and write permissions. My question is how can I extract the permissions of a process from the proc/.../maps file?</p>
  
  <p>Here is a snippet of my code where I am having trouble:</p>
  
  <pre><code>sprintf(buf, "/proc/%d/maps", tgid-&gt;d_name); 
  file = fopen(buf, "r");
  
  while (fgets(buf, sizeof(buf), file)) {
      sscanf(buf, "%x-%x %4c %x %x:%x", &amp;from, &amp;to, flags, &amp;offset, &amp;major, &amp;minor);
  }
  
  fclose(file);
  if (flags[0] == 'r' &amp;&amp; flags[1] == 'w') {
      printf("%d\n", tgid-&gt;d_name);
  }      
  </code></pre>