是否存在用于获取正在运行的进程的uid/gid的系统调用? [英] Is there a system call for obtaining the uid/gid of a running process?

查看:28
本文介绍了是否存在用于获取正在运行的进程的uid/gid的系统调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我自己的问题的长答案是,用Google搜索它,但没有发现任何有用的东西,这是为了筛选"ps"的来源.但是在我这样做之前,是否有人愿意提供这个懒人的解决方案?:-)

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? :-)

我发现了以下问题:使用procf/<了解流程状态; pid>/status 但是,该解决方案似乎在3.2内核上不可用.在较新的内核中可以使用此pstatus_t类型吗?如果是这样,这是否意味着较新的内核为/proc//status提供了二进制接口?

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);
}

这篇关于是否存在用于获取正在运行的进程的uid/gid的系统调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆