🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #1037

Re: the entrance of the process table

#1037
From: Keith Gabryelski
Date: Tue, 16 Oct 1990 20:34
49 lines
1851 bytes
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.
Technical Details
Message-ID: <15187@cbmvax.commodore.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!psuvax1!rutgers!cbmvax!ag
References: <31229@netnews.upenn.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!psuvax1!rutgers!cbmvax!ag
From: ag@cbmvax.commodore.com (Keith Gabryelski)
Newsgroups: comp.unix.programmer
Subject: Re: the entrance of the process table
Message-ID: <15187@cbmvax.commodore.com>
Date: 16 Oct 90 20:34:17 GMT
References: <31229@netnews.upenn.edu>
Reply-To: ag@cbmvax.commodore.com (Keith Gabryelski)
Organization: Commodore-Amiga Unix; West Chester, PA
Lines: 49