[comp.unix.microport] process ids

jbayer@ispi.UUCP (id for use with uunet/usenet) (09/02/88)

	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.

	Anybody have any ideas?

Jonathan Bayer
Intelligent Software Products, Inc.	(Don't ask me, I only work here)
19 Virginia Ave.
Rockville Centre, NY   11570
uunet!ispi!jbayer

mike@sleepy.unm.edu (Michael I. Bushnell) (09/02/88)

In article <171@ispi.UUCP> jbayer@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@turing.unm.edu
	    {ucbvax,gatech}!unmvax!turing.unm.edu!mike

leo@philmds.UUCP (Leo de Wit) (09/02/88)

In article <171@ispi.UUCP> jbayer@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.
|
|	Anybody have any ideas?

See the manual pages of getpgrp(2), killpg(2), setpgrp(2).
And getppid(2) for the parent process id (not needed to kill the group).

          Leo.

haugj@pigs.UUCP (The Beach Bum) (09/03/88)

In article <171@ispi.UUCP> jbayer@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.

>	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.

anyone interested in playing with system tables should pick up my crash
program which was posted in comp.sources.misc earlier this summer.  it
contains code which will determine the process group id and parent
process id.

if you are interested in any other kernel table munging this program is
a good source of ideas ...
-- 
=-=-=-=-=-=-=-The Beach Bum at The Big "D" Home for Wayward Hackers-=-=-=-=-=-=
               Very Long Address: John.F.Haugh@rpp386.dallas.tx.us
                         Very Short Address: jfh@rpp386
                           "ANSI C: Just say no" -- Me

mouse@mcgill-vision.UUCP (der Mouse) (09/11/88)

In article <787@philmds.UUCP>, leo@philmds.UUCP (Leo de Wit) writes:
> In article <171@ispi.UUCP> jbayer@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 idea is to be able to kill
>> an entire process group with one kill().

Look at killpg().  Or use the negative of the process group number as
the process ID.  Or do you mean something else by "process group"?

If you reall want to dig this out of the kernel, you'll need to play
games with nlist and /dev/kmem the way ps does.

> See the manual page[s] [for] getppid(2) for the parent process id

getppid() gets the process ID of the parent of *its caller*.  It can't
be used to obtain the parent process ID of any other process.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu