扫描给定PID列表并确定执行用户的应用程序
findProcessOwner的Python项目详细描述
扫描给定PID列表并确定执行用户的应用程序。
stdout上的每一行都包含结果,要么是用户名或uid(如果指定了–uid,或者用户名不能由uid确定),要么是完全失败时的“未知”(如无效的pid)。
错误消息位于同一行,但在stderr中,这样任何脚本都可以使用stdout结果,只需检查“未知”,而不需要分析错误。
用法
Usage: findProcessOwner (options) [pid1] (optional: pid2, pid3)
Prints the owner (account running) processes, given their pids. They are returned one per line on stdout.
Any errors reported go to stderr. If no owner can be determined, stdout will contain “unknown” for that line.
Thus your program can always ensure parsable output by parsing stdout, one-entry per line, and checking for “unknown”.
If a username can not be determined (like user deleted, or uid changed, etc) a pid will be printed.
Options:
–uid Print the UID instead of the username
–version Print the version
示例:
findProcessOwner 1234
findProcessOwner –uid 1234 3231
返回:
Returns zero if all searches were successful, otherwise non-zero.
示例
当前shell用户:
$] findProcessOwner $$
myuser
三个进程,两个无效:
$] findProcessOwner 12345 $$ 12233
unknown (Could not determine owner of pid 12345)
myuser
unknown (Could not determine owner of pid 12233)
三个进程,两个无效,stderr无效:
$] findProcessOwner 12345 $$ 12233 2>/dev/null
unknown
myuser
unknown