如下所示,每个进程都有名字:
crash> ps -k
PID PPID CPU TASK ST %MEM VSZ RSS COMM
743 2 1 ee1c9400 IN 0.0 0 0 [BPLOGwqL1]
744 2 1 ee144000 IN 0.0 0 0 [BPLOGwqL23]
1982 1 0 e35aac00 UN 0.1 1828 1068 tty_trans
1983 1 0 dd00c000 IN 0.1 1828 1068 tty_trans
crash> task_struct.comm
struct task_struct {
[724] char comm[16]; /*comm成员表示进程的名字*/
}
#define kthread_create(threadfn, data, namefmt, arg...) \
kthread_create_on_node(threadfn, data, -1, namefmt, ##arg)
struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
void *data,
int node,
const char namefmt[],
...)
-> vsnprintf(create.result->comm, sizeof(create.result->comm),
namefmt, args);
load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
-> setup_new_exec(bprm)
-> set_task_comm(current, bprm->tcomm);/*名字来自可执行文件的名字*/
crash> ps -k
PID PPID CPU TASK ST %MEM VSZ RSS COMM
743 2 1 ee1c9400 IN 0.0 0 0 [BPLOGwqL1]
744 2 1 ee144000 IN 0.0 0 0 [BPLOGwqL23]
1982 1 0 e35aac00 UN 0.1 1828 1068 tty_trans
1983 1 0 dd00c000 IN 0.1 1828 1068 tty_trans
crash> task_struct.comm
struct task_struct {
[724] char comm[16]; /*comm成员表示进程的名字*/
}
这个名字是哪里赋值的?
对内核进程
是直接输入的,如 create_workqueue("BPLOGwqL1");#define kthread_create(threadfn, data, namefmt, arg...) \
kthread_create_on_node(threadfn, data, -1, namefmt, ##arg)
struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
void *data,
int node,
const char namefmt[],
...)
-> vsnprintf(create.result->comm, sizeof(create.result->comm),
namefmt, args);
对用户进程:
对ELF格式的文件:load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
-> setup_new_exec(bprm)
-> set_task_comm(current, bprm->tcomm);/*名字来自可执行文件的名字*/