linux从内核中的pid获取进程名称

Mal*_* N. 6 linux linux-kernel

您好我在内核中使用sys_getpid()获取进程ID如何从内核结构中找到进程名?它存在于内核中吗?

非常感谢

Zim*_*bao 14

struct task_struct包含一个名为comm的成员,它包含executable name excluding path.

从此文件中获取当前宏将获取启动当前进程的程序的名称(如insmod/modprobe中所示).

使用以上信息,您可以使用获取名称信息.

  • `current->comm` 包含线程名称。可以通过 pthread_setname_np 或相应的系统调用来更改。 (2认同)