Full process name from task_struct

前端 未结 2 1940
抹茶落季
抹茶落季 2021-02-08 08:32

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 t

相关标签:
2条回答
  • 2021-02-08 09:27

    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);
    }
    
    0 讨论(0)
  • 2021-02-08 09:29

    Just use current->comm and you can see the name.

    Example:

    printk(KERN_ALERT "THREAD NAME = %s\n", current->comm);
    
    0 讨论(0)
提交回复
热议问题