the entrance of the process table

Keith Gabryelski ag at cbmvax.commodore.com
Wed Oct 17 06:34:17 AEST 1990


In article <31229 at netnews.upenn.edu> xiang at grad1.cis.upenn.edu (Xiang Ge)
writes:
>The process table is a linked list.

Actually it is an array on all unix implementations I am aware of.
Each entry may have links to siblings or children, but it is probably
more use for you to think about it as an array.

>Can any body tell my how to get the head of this list, or any other
>way to get the entrance of the process table.

Depends on your system.  Try:

	If you are on a System V system nlist for `proc' and `v'.
	From `v' get v.nproc (sys/var.h).

	If you are on a BSD system nlist for `proc' and `nproc'.


	Now, if proc_addr is the symbol address you got from nlisting
	for `proc' AND nproc is the symbol adress you got from nlisting
	for `nproc' (or if on System V you nlisted for `v' then read
	that struct in and got `v.nproc'), then:

	if ((fd = open("/dev/kmem", O_RDONLY)) < 0)
	{
		perror("open /dev/kmem");
		exit(1);
	}

#ifdef INDIRECTION_ON_PROC
	lseek(fd, proc_addr, 0);
	read(fd, proc_addr, sizeof(struct proc * ));
#endif

	myproc = (struct proc *)malloc(sizeof(struct proc) * nproc);
	if (!myproc)
	{
		perror("malloc failed");
		exit(1);
	}

	lseek(fd, proc_addr, 0);

	read(fd, myproc, sizeof(struct proc) * nproc);

Pax, Keith

Ps, on some system `proc' will be `_proc', etc.



More information about the Comp.unix.programmer mailing list