来自task_struct的完整进程名称 [英] Full process name from task_struct

查看:56
本文介绍了来自task_struct的完整进程名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从struct task_struct获取完整的进程名称. comm字段仅存储16个字符,而进程名称可以更长.有什么办法可以获取完整的进程名称?
这可以通过从task_struct获取struct vm_area_struct并进一步获取vm_area映射到的文件来完成,但这是不可靠的.

I want to get full process name from struct task_struct. The comm field stores only 16 characters, while process name can be longer. Is there any way to get full process name?
This can be done through by getting struct vm_area_struct from task_struct, and further obtain file to which vm_area is mapped, but this is unreliable.

推荐答案

您是指exe文件名吗?您可以按以下方式获取当前进程的exe:

Did you mean exe file name? You can get the exe of current process as follows :

char *pathname,*p;
mm = current->mm;
if (mm) {
    down_read(&mm->mmap_sem);
    if (mm->exe_file) {
                pathname = kmalloc(PATH_MAX, GFP_ATOMIC);
                if (pathname) {
                      p = d_path(&mm->exe_file->f_path, pathname, PATH_MAX);
                    /*Now you have the path name of exe in p*/
                }
            }
    up_read(&mm->mmap_sem);
}

这篇关于来自task_struct的完整进程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆