在solaris 11.0內核模塊驅動程序中,我需要獲取父進程ID和啓動時間,並繼續執行此操作 - 以這種方式爬上進程樹。在solaris內核模塊中獲取進程ID和父進程
在Linux內核中我有struct_task包含進程ID,啓動時間。
什麼是struct_task的等價物,以及如何在流程上下文中獲取它?
感謝
我看到的東西像什麼,我需要但用戶空間。但「開放」不能在內核空間使用..
char psfile[64];
pid_t pid;
int fd;
psinfo_t psinfo;
pid = getpid();
sprintf(psfile, "/proc/%d/psinfo", pid);
if ((fd = open(psfile, O_RDONLY)) >= 0) {
if (read(fd, &psinfo, sizeof(psinfo_t)) != -1) {
printf("Pid: %ld\n", psinfo.pr_pid);
printf("Up Start: (%ld, %ld)\n", psinfo.pr_start.tv_sec,
psinfo.pr_start.tv_nsec);
printf("Command: %s\n", psinfo.pr_fname);
return 0;
}
} else {
perror("Open psfino");
}
的/ proc/PROCID /中psinfo的整個概念是允許用戶空間的進程讀取內核數據。由於im在內核空間,我需要從/ proc/procid/psinfo獲取數據,如果im在內核空間,這是磁盤IO我避免...
你看過getppid()嗎? –
我不能使用fd = open(psfile,O_RDONLY))> = 0)。我得到的信息是開放無效,這是正確的方式嗎?打開/ proc /「getppid()」/ psinfo並獲取數據?從內核空間還? – ilansch
您的程序是否有權執行此操作?最後我知道,/ proc /被保護了。 –