Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full process name from task_struct

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.

like image 443
mhl Avatar asked Sep 06 '13 12:09

mhl


1 Answers

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);
}
like image 89
PaulDaviesC Avatar answered Nov 16 '22 18:11

PaulDaviesC