查找进程的pidLinux认证考试

文章作者 100test 发表时间 2009:08:21 19:04:41
来源 100Test.Com百考试题网


  注意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("Cant find the process named %s,you should run it in advance\n",ps_name).
  return -1.
  p_find:
  return pid.
  }

相关文章


如何在64位的Linux中运行32位的应用程序Linux认证考试
linuxqmail病毒_垃圾邮件处理Linux认证考试
在BSD上安装Nfsen网络流量工具Linux认证考试
删除Linux系统下的历史记录Linux认证考试
查找进程的pidLinux认证考试
kernel中的双链表的使用Linux认证考试
unix_Linux低级IO函数的用法Linux认证考试
用Perl从oracle导出百万级数据到excelLinux认证考试
将LINUX变成路由器Linux认证考试
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛