获取内核中当前正在运行的程序的绝对路径 [英] Get the absolute path of current running program in kernel
本文介绍了获取内核中当前正在运行的程序的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了检索正在运行的程序的文件权限,我需要在当前正在运行的程序上执行kstat
.然后我需要加载ELF图像的绝对路径.
In order to retrieve file permissions of the running program, I need to do a kstat
on the program currently running. Then I need to get the absolute path of the ELF image loaded.
有可能吗? current->comm
仅记录不带路径的程序名称.
Is that possible? current->comm
only records the program name without path.
或者还有其他方法可以做到吗?
Or what other ways to do it?
推荐答案
您可以readlink(2)
带有/proc/self/exe
的路径,在您的情况下,这将是指向ELF的链接.使用readlink(1)
的元示例:
You can readlink(2)
with the path to /proc/self/exe
, which in your case would be a link to the ELF. Metaexample using readlink(1)
:
$ readlink /proc/self/exe
/bin/readlink
据我所知,仅适用于Linux.
Linux-only as far as I know.
这篇关于获取内核中当前正在运行的程序的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文