- 论坛徽章:
- 0
|
我怀疑是少装了什么库,
谁能不能把这个头文件发过来?
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
源代码如下:
- /*
- * Includes
- */
- #include <stdlib.h>;
- #include <stdio.h>;
- #include <unistd.h>;
- #include <errno.h>;
- #include <fcntl.h>; /* for O_RDONLY */
- #include <sys/signal.h>;
- #include <sys/fault.h>;
- #include <sys/syscall.h>;
- #include <sys/procfs.h>; /* for PIOCPSINFO and prpsinfo_t */
- #include <sys/ioctl.h>;
- #include <time.h>;
- /* ----------------------------------------------------------------------------
- * Check given process is alive, return pid if so, else return 0.
- * Return -1 for error, or pid if status cannot be accessed (no KVM or PROCFS).
- * May also be able to return start time of process if alive.
- * Does not set starttime if pointer is NULL.
- */
- pid_t
- Process_Alive(pid_t pid, time_t *starttime)
- {
- int fd, rc;
- char filename[FILENAME_MAX];
- prpsinfo_t psinfo;
- sprintf(filename, "/proc/%d", pid);
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- {
- if (errno == ENOENT)
- pid = 0;
- else
- pid = -1;
- }
- else
- {
- rc = ioctl(fd, PIOCPSINFO, &psinfo);
- if (rc < 0)
- {
- printf( "Cannot get process info from procfs");
- if (errno == ENOENT)
- pid = 0;
- else
- pid = -1;
- }
- else
- {
- if (psinfo.pr_zomb)
- pid = 0;
- }
- close(fd);
- }
-
- return(pid);
- }
- int main(int argc, char *argv[])
- {
- pid_t pid;
- pid_t rc;
- time_t tim;
- if (argc!=2){fprintf(stderr,"usage: pid <pid>;\n");exit(1);}
- pid = (pid_t)atoi(argv[1]);
- rc = Process_Alive(pid, &tim);
- printf("pid=%d, rc=%d, time=%s", pid, rc, ctime(&tim));
- return(0);
- }
复制代码 |
|