Path: utzoo!attcan!uunet!ginosko!uakari.primate.wisc.edu!pikes!boulder!ccncsu!handel.cs.colostate.edu!wendt From: wendt@handel.cs.colostate.edu (alan l wendt) Newsgroups: alt.sources Subject: How to read stuff in the kernel. Message-ID: <2698@ccncsu.ColoState.EDU> Date: 24 Sep 89 00:29:10 GMT Sender: news@ccncsu.ColoState.EDU Reply-To: wendt@handel.cs.colostate.edu (alan l wendt) Distribution: alt Organization: Colorado State University Lines: 43 /* This program prints out a list of all currently active process ids. */ /* It is intended as an example of how (on Sys V Venix) to access data */ /* out of the kernel's address space. */ /* Alan Wendt */ #include#include #include #include struct nlist nl[] = { { "_proc" }, { "_v" }, { "" } }; main() { struct proc proc; long p; int f; int i; struct var v; f = open("/dev/kmem", 0); /* should check this */ nlist("/venix", nl); /* get some symbol values */ /* from the kernel's symbol table */ lseek(f, (long)nl[1].n_value, 0); read(f, &v, sizeof(v)); /* read the "v" structure */ for (p = nl[0].n_value, i = 0; i < v.v_proc ;p += sizeof(struct proc), i++) { lseek(f, p, 0); read(f, &proc, sizeof(proc)); /* read a process table entry */ if (proc.p_stat) printf("%d ", proc.p_pid); } exit(0); }