*BSD News Article 25244


Return to BSD News archive

Xref: sserve comp.unix.ultrix:20809 comp.unix.bsd:13165 comp.unix.programmer:13820 comp.unix.questions:43450
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!howland.reston.ans.net!gatech!concert!news.duke.edu!gallatin
From: gallatin@davinci.isds.duke.edu (Andrew Gallatin)
Newsgroups: comp.unix.ultrix,comp.unix.bsd,comp.unix.programmer,comp.unix.questions
Subject: how to get a proc's tty info
Message-ID: <25611@news.duke.edu>
Date: 22 Dec 93 01:33:49 GMT
Sender: news@news.duke.edu
Followup-To: comp.unix.ultrix
Organization: Institute of Statistics and Decision Sciences
Lines: 33
Nntp-Posting-Host: davinci.isds.duke.edu
Originator: gallatin@davinci.isds.duke.edu


I'm running Ultrix 4.2, and sometimes utmp entries don't get cleared
when a user logs off.  This results in funny output from who,
finger..etc.  As a learning experience, I'm trying to write a program
that will clear a utmp entry, write a wtmp entry, and chmod/chown the
tty in question.

My problem is: Given a process id, or a proc struct, how can one get
the controlling tty?  

I have managed to get as far as going through the process table, and
looking at all the proc structs.  The most obvious thing to do would
be to look at *p_ttyp entry of the proc struct. However, it seems to be
in kernel space, and I get:

pid 16438 (a.out) was killed on a kernel access, at pc 0x4003f0 

when I try to access it. (yes, this is running as root, I need to open
/dev/kmem to read the process table)

I know it must be possible to get the tty info, (ps does it), but I
can't seem to find the right system call.  Is there a version of ps
for ultrix with public source code? Can anybody help?

Thanks!

Drew
##############################################################################
#		Andrew Gallatin, System Administrator			     #
#	    Institute of Statistics and Decision Sciences		     #
#	  Box 90251, Duke University, Durham, NC 27708-0251		     #
#		    email:  gallatin@isds.duke.edu			     #
##############################################################################