ps 如何显示 Mac OS X 上所有进程的 argv?
我试图根据 Mac OS X 上的参数来确定特定进程何时运行。可能有多个进程以相同的名称运行,但只有一个进程具有我正在查找的参数。这些进程不属于将运行我的代码的同一用户。他们不会以任何方式修改他们的argv。
“ps”命令准确地显示了我需要的信息。但我非常希望不必生成“ps”并解析其输出。
我最初尝试了这个问题中的解决方案,使用sysctl,但事实证明它只适用于您拥有的进程;有关详细信息,请参阅我的其他问题。
那么ps如何获取其他用户拥有的进程的argv信息呢?
I'm trying to identify when a particular process is running, based on its arguments, on Mac OS X. There may be several processes running with the same name, but only one will have the arguments I'm looking for. The processes are not owned by the same user who will be running my code. They will not have modified their argv in any way.
The 'ps' command shows exactly the information that I need. But I would greatly prefer not to have to spawn 'ps' and parse its output.
I originally tried the solution from this question, using sysctl, but it turns out that only works for processes you own; see my other question for more info.
So how does ps obtain argv information for processes owned by other users?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Mac OS X ps 上,setuid 0 是它获取所有进程信息的方式。您必须以 root 身份运行才能获取该信息,因此您需要 setuid 0 或使用 sudo 运行实用程序。
最好的方法可能就是生成 ps 并解析输出,即使您真的不想这样做;)
On Mac OS X ps is setuid 0, which is how it gets the information for all the processes. You have to run as root to get that information, so either you need to be setuid 0 or run your utility with sudo.
The best way is probably just to spawn ps and parse the output, even if you don't really want to ;)
BSD
ps
(在 Mac OS X 中使用)使用kvm_getargv()
获取进程的命令行参数。这是实际的调用: ps 源代码。搜索
kvm_getproc2
。请参阅 该函数系列的 OpenBSD 手册页。
BSD
ps
(used in Mac OS X) useskvm_getargv()
to get the commandline arguments for a process.Here is the actual call: ps source code. Search for
kvm_getproc2
.See OpenBSD man page for this family of functions.