The full process name from task_struct

I want to get the full process name from struct task_struct . The comm field holds only 16 characters, and the process name can be longer. Is there a way to get the full name of the process?
This can be done by getting struct vm_area_struct from task_struct and getting the file to which vm_area is mapped, but this is unreliable.

+9
linux process kernel
source share
2 answers

Did you mean exe file name? You can get exe of the 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); } 
+12
source share

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

Example:

 printk(KERN_ALERT "THREAD NAME = %s\n", current->comm); 
-2
source share

All Articles