注意2.4和2.6 kernel的struct task_struct 已经发生变化了。 原来2.4里面的struct task_struct *task_next 已经没有了, 变成了现在的struct list_head tasks 了。 所以编程时候要注意。 /* By process name , you can get task_struct for which wake up ,bob added */ int self_find_task_by_name(char *ps_name) { pid_t pid = -1. // int counter = 0. //2.4 //struct task_struct *p = current->.next_task. //struct task_struct *p_query_head = current . //2.6 struct list_head *p = NULL. struct list_head *head = &.current->.tasks. //loop times depends on the number of the process in current system //2.4 //while(p != NULL &.&. p->.pid != p_query_head->.pid) //2.6 kernel list_for_each(p,head) { #define this_task(p) list_entry(p,struct task_struct, tasks) //我自己定义的一个宏 ,可以直接把list_head 指针的宿主指针找出来。来源:考试大 struct task_struct *task = NULL. task = this_task(p). if( ! memcmp(task->.comm,ps_name,strlen(ps_name))) { pid = task->.pid. goto p_find. } } dbg("Can t find the process named %s,you should run it in advance\n",ps_name). return -1. p_find: return pid. }