免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2041 | 回复: 0
打印 上一主题 下一主题

PIOCPSINFO 没有定义? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-09-16 16:29 |只看该作者 |倒序浏览
我怀疑是少装了什么库,
谁能不能把这个头文件发过来?


xiangshifu##hotmail.com

操作系统: suse linux
Linux version 2.6.5-7.97-default (geeko@buildhost) (gcc version 3.3.3 (SuSE Linux)) #1 Fri Jul 2 14:21:59 UTC 2004


源代码如下:




  1. /*
  2. * Includes
  3. */
  4. #include <stdlib.h>;
  5. #include <stdio.h>;
  6. #include <unistd.h>;
  7. #include <errno.h>;

  8. #include <fcntl.h>;            /* for O_RDONLY */
  9. #include <sys/signal.h>;
  10. #include <sys/fault.h>;
  11. #include <sys/syscall.h>;
  12. #include <sys/procfs.h>;       /* for PIOCPSINFO and prpsinfo_t */
  13. #include <sys/ioctl.h>;
  14. #include <time.h>;


  15. /* ----------------------------------------------------------------------------
  16. * Check given process is alive, return pid if so, else return 0.
  17. * Return -1 for error, or pid if status cannot be accessed (no KVM or PROCFS).
  18. * May also be able to return start time of process if alive.
  19. * Does not set starttime if pointer is NULL.
  20. */
  21. pid_t
  22. Process_Alive(pid_t pid, time_t *starttime)
  23. {

  24.                 int fd, rc;
  25.                 char filename[FILENAME_MAX];
  26.                 prpsinfo_t psinfo;
  27.                 sprintf(filename, "/proc/%d", pid);
  28.                 fd = open(filename, O_RDONLY);
  29.                 if (fd < 0)
  30.                 {
  31.                         if (errno == ENOENT)
  32.                                 pid = 0;
  33.                         else
  34.                                 pid = -1;
  35.                 }
  36.                 else
  37.                 {
  38.                         rc = ioctl(fd, PIOCPSINFO, &psinfo);
  39.                         if (rc < 0)
  40.                         {
  41.                                 printf( "Cannot get process info from procfs");
  42.                                 if (errno == ENOENT)
  43.                                         pid = 0;
  44.                                 else
  45.                                         pid = -1;
  46.                         }
  47.                         else
  48.                         {
  49.                                 if (psinfo.pr_zomb)
  50.                                         pid = 0;
  51.                         }
  52.                         close(fd);
  53.                 }
  54.        

  55.         return(pid);
  56. }



  57. int main(int argc, char *argv[])
  58. {
  59.         pid_t pid;
  60.         pid_t rc;
  61.         time_t tim;
  62.         if (argc!=2){fprintf(stderr,"usage: pid <pid>;\n");exit(1);}
  63.         pid = (pid_t)atoi(argv[1]);
  64.         rc = Process_Alive(pid, &tim);
  65.         printf("pid=%d, rc=%d, time=%s", pid, rc, ctime(&tim));
  66.         return(0);
  67. }




复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP