How to read stuff in the kernel.

alan l wendt wendt at handel.cs.colostate.edu
Sun Sep 24 10:29:10 AEST 1989


/*  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 <nlist.h>
#include <sys/types.h>
#include <sys/proc.h>
#include <sys/var.h>

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);
    }



More information about the Alt.sources mailing list