The long answer to my own question, having Googled it and not found anything useful, is to sift through the source of 'ps'. But before I do that, is there anyone willing to provide the lazy man's solution? :-)
I found this question: Knowing the process status using procf/<pid>/status However, the solution doesn't seem to be available on the 3.2 kernel. Is this pstatus_t type available in newer kernels? If so, does that mean newer kernels provide a binary interface to /proc//status?
At the moment, the only viable solution I can come up with is something along the lines of this. Obviously, not gone to the effort to see if this actually works as I would expect it to yet...:
int len, pid, n, fd = open("/proc/12345/status", O_RDONLY | O_NOATIME);
char buf[4096], whitespace[50];
if (0 < (len = read(fd, buf, 4096)))
{
n = sscanf(buf, "Uid:%s%d ", whitespace, &pid);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With