Right now, the only viable solution I can come up with is something like this. Obviously, I didn’t make an attempt to see if this really works, as I would expect this ...:
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); }
source share