从pid获取应用程序的真实路径?
如何获取流程详细信息,例如应用程序名称和名称?来自进程ID的应用程序的真实路径?
我使用的是 Mac OS X。
How can I get the process details like name of application & real path of application from process id?
I am using Mac OS X.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您知道 PID,则很容易获取进程名称/位置,只需使用 proc_name 或 proc_pidpath 即可。看一下下面的示例,它提供了流程路径:
It's quite easy to get the process name / location if you know the PID, just use proc_name or proc_pidpath. Have a look at the following example, which provides the process path:
您可以使用活动监视器 - http://en.wikipedia.org/wiki/Activity_Monitor
或者在终端应用程序中,您可以使用:
PID
是您要查找的进程ID有关 'ps` 命令的更多帮助,您可以找到
You can use the Activity Monitor - http://en.wikipedia.org/wiki/Activity_Monitor
Or in the Terminal App you can use:
PID
is the process id you are looking forMore help on 'ps`command you can find with
尝试使用 lsof
示例:
lsof -p 1066 -Fn | awk 'NR==2{打印}' | sed "s/n\//\//"
输出:
/Users/user/Library/Application Support/Sublime Text 2/Packages
Try use lsof
example:
lsof -p 1066 -Fn | awk 'NR==2{print}' | sed "s/n\//\//"
output:
/Users/user/Library/Application Support/Sublime Text 2/Packages
如果PID是“用户应用程序”的PID,那么您可以像这样获取应用程序的
NSRunningApplication
:并打印可执行文件的路径:
应用程序包本身在这里
但是这赢了不能与系统或后台进程一起使用,它仅限于用户应用程序(通常在启动后在扩展坞中可见的应用程序)。 NSRunningApplication 对象允许检查应用程序是否是主动的、隐藏/取消隐藏它以及执行所有其他类型的简洁操作。
只是想我在这里提到它是为了完整性。如果您想使用任意进程,那么接受的答案当然更好。
If the PID is the PID of a "user application", then you can get the
NSRunningApplication
of the app like that:And to print the path of the executable:
the app bundle itself is here
However this won't work with system or background processes, it's limited to user apps (those typically visible in the dock after launch). The
NSRunningApplication
object allows to to check if the app is ative, to hide/unhide it and do all other kind of neat stuff.Just thought I mention it here for completeness. If you want to work with arbitrary processes, then the accepted answer is of course better.
我想只在 bash 中制作一个更好的 ssh-copy-id!
为此,我必须知道 sshd 在哪里才能询问他的实际配置。
在某些系统上,我有多个 sshd,但这不是我的朋友。
此外,在某些 macOS 上,ps 命令不显示 sshd 的完整路径。
此返回之后返回
在我可以要求
,在某些系统上
,所以我必须输入 .ssh/authorized_keys
I would like to make a better ssh-copy-id in bash only!!
For that, i have to know where is sshd to ask him his actual config.
On some system i have multiple sshd and which is not my friend.
Also on some macOS the ps command didn't show the full path for sshd.
this return
after i could ask for
this return, on some system
so i have to put in .ssh/authorized_keys