[英]Is there a function in C to get the current process's virtual runtime on Linux?
TL;DR: TL;博士:
What would be the best way to:什么是最好的方法:
vruntime
value?vruntime
值? I'm trying to implement a new system call (in C) which will return the virtual runtime of the current process.我正在尝试实现一个新的系统调用(在 C 中),它将返回当前进程的虚拟运行时。
The virtual runtime is stored in the vruntime
field in the process's PCB, but I couldn't find how to access it.虚拟运行时存储在进程 PCB 的
vruntime
字段中,但我找不到如何访问它。
I've been trying to find a way using the process's PID or the process name itself without success.我一直在尝试找到一种使用进程的 PID 或进程名称本身的方法,但没有成功。 Is there a way to get the process as a
struct task_struct
variable and access the vruntime
field?有没有办法将进程作为
struct task_struct
变量并访问vruntime
字段?
There is already one, getrusage(RUSAGE_SELF, &rusage)
, implemented in kernel/sys.c:getrusage() .已经有一个
getrusage(RUSAGE_SELF, &rusage)
在kernel/sys.c:getrusage()中实现。
Your system call will be running in kernel mode in the context of the thread that invoked it, so the following expression will get the current process task_struct:您的系统调用将在调用它的线程上下文中以 kernel 模式运行,因此以下表达式将获取当前进程 task_struct:
current_thread_info() -> task
You can then read the vruntime field to a buffer provided by the user, using copy_to_user
or similar for safety with respect to untrusted addresses from the caller.然后,您可以使用
copy_to_user
或类似方法将 vruntime 字段读取到用户提供的缓冲区,以确保来自调用者的不受信任地址的安全。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.