process ids

Michael I. Bushnell mike at sleepy.unm.edu
Fri Sep 2 16:43:08 AEST 1988


In article <171 at ispi.UUCP> jbayer at ispi.UUCP (id for use with uunet/usenet) writes:
>
>	I have a need to be able to identify the parent of a process
>which is executing on the system.  The program which will be doing the
>identification will not be either the owner, or even the same user. 
>However, it will have root privilages.  The idea is to be able to kill
>an entire process group with one kill().  I know it's available
>somewhere since ps is able to display it.  
>
>	I have found an include file	<sys/proc.h>	which apparently
>is used by the system to keep track of this.  I can find no reference to
>it in any manual I have looked in.

If you want to kill a process group, then kill with a negative argument will
do that.  If you just want the parent for another reason (to kill an
entire process hierarchy, or whatever), then do the following:

Using nlist(3), find the symbol _proc and _nproc in /vmunix.  Read 
from /dev/kmem a longword from _proc and _nproc.  _proc contains the
address of the process table and _nproc contains the size.  Then read
the process table (it is sizeof(struct proc) * nproc) in size...

Search one by one.  Check each record to see if it is a real process
(p_stat != 0).  Then, check if it is the process you want and then
look at its parent.
-- 
                N u m q u a m   G l o r i a   D e o 

			Michael I. Bushnell
			HASA - "A" division
			mike at turing.unm.edu
	    {ucbvax,gatech}!unmvax!turing.unm.edu!mike



More information about the Comp.unix.questions mailing list