[comp.unix.programmer] the entrance of the process table

xiang@grad1.cis.upenn.edu (Xiang Ge) (10/16/90)

The process table is a linked list. 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.

Thank you in advance !

xg

jackv@turnkey.tcc.com (Jack F. Vogel) (10/17/90)

In article <31229@netnews.upenn.edu> xiang@grad1.cis.upenn.edu (Xiang Ge) writes:
>The process table is a linked list. 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.
 

A simple glance at proc.h would give you your answer. Following the proc
structure definition you will find a declaration such as the following:

	extern struct proc proc[];
		-or-
	extern struct proc *proc;

Clear enough?


-- 
Jack F. Vogel			jackv@locus.com
AIX370 Technical Support	       - or -
Locus Computing Corp.		jackv@turnkey.TCC.COM

ag@cbmvax.commodore.com (Keith Gabryelski) (10/17/90)

In article <31229@netnews.upenn.edu> xiang@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.