在外企做服务器开发, 目前是项目经理, 管理两个server开发的项目。不做嵌入式好久了。
全部博文(197)
分类: LINUX
2007-09-28 12:49:06
/* 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 = ¤t->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; } |