Is it possible to get hold of a process's Process control Block given

John F. Haugh II jfh at rpp386.UUCP
Sat Aug 6 00:07:27 AEST 1988


In article <429 at alice.marlow.uucp> fox at marlow.UUCP (Paul Fox) writes:
>That answers your question (albeit badly)...can anybody answer
>mine... I am trying to write/port the BSD 'top' utility
>posted to usenet sometime ago, to Unix V.3. 

who knows ...

the relevant area of the process table entry is p_addr.  on some
systems this is a union, with one part for the core address, and
another for the swap address.  select the appropriate one by looking
at p_stat.

if you post your source (or mail me a copy) i should be able to get
it ported to sco xenix in 10 or 15 minutes ;-)  below is my solution
to finding a user page.  it is cut from a soon to be posted crash
command.  ignore most of the cruft.  the includes should give you an
idea of where to look for hints as to how to get this to work.
----- crash/user.c -----
#include <sys/param.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <sys/page.h>
#include <sys/seg.h>
#include <sys/file.h>
#include <sys/proc.h>
#include <sys/signal.h>
#include <sys/dir.h>
#include <sys/user.h>
#include <sys/var.h>
#include <sys/lock.h>
#include "crash.h"

findu (proc, slot, user)
struct	proc	*proc;
int	slot;
struct	user	*user;
{
	struct	proc	*procs = (struct proc *) namelist[NM_PROC].xl_value;
	long	swapaddr;
	int	i;

	if ((proc->p_flag & (SSWAP|SSPART)) || ! (proc->p_flag & SLOAD)) {
		swapaddr = proc->p_addr[0].te_frameno * NBPC;
		l_lseek (swapfd, swapaddr, 0);
		r_read (swapfd, user, sizeof *user);
	} else {
		l_lseek (memfd, proc->p_addr[0].te_frameno * NBPC, 0);
		r_read (memfd, user, sizeof *user);
	}
	if (user->u_procp - procs == slot)
		return (1);
	else
		return (0);
}

/* rest deleted */
-- 
John F. Haugh II                 +--------- Cute Chocolate Quote ---------
HASA, "S" Division               | "USENET should not be confused with
UUCP:   killer!rpp386!jfh        |  something that matters, like CHOCOLATE"
DOMAIN: jfh at rpp386.uucp          |         -- apologizes to Dennis O'Connor



More information about the Comp.unix.wizards mailing list