How to get login shell pid's

Mikel Manitius mikel at codas.UUCP
Sun Oct 6 07:53:43 AEST 1985


> Here's the story:
> 
> I'm writing my own version of "idledaemon" but I'd like a few suggestions from
> the net. Namely, what's the best way to get the pid of a users login shell? The
> SystemV command 'who -u' supplies the number, but I can't find anything in the
> 4.2 BSD universe that does the same. Any suggestions? Any idea how AT&T does
> it in 'who', and can it be done similarly in 4.2 BSD?
> 
> Thanx.
> -- 
> -------------------------------------------------------------------------------
>       allegra\					       Dave Bloom
>       harvard \ pyramid\
>        seismo  \  pyrnj >!andromeda!dave         HOME: (201) 868-1764
>      ut-sally   >!topaz/			 WORK: (201) 648-5083
>        sri-iu  /
> ihnp4!packard /		           "You're never alone with a schizophrenic...."

Under System V, the login shell's pid is stored in /etc/utmp, the follwing
is the contents of /usr/include/utmp.h
-------
/*	@(#)utmp.h	1.2	*/
/*	@(#)utmp.h	3.2	*/

/*	<sys/types.h> must be included.					*/

#define	UTMP_FILE	"/etc/utmp"
#define	WTMP_FILE	"/etc/wtmp"
#define	ut_name	ut_user

struct utmp
  {
	char ut_user[8] ;		/* User login name */
	char ut_id[4] ; 		/* /etc/lines id(usually line #) */
	char ut_line[12] ;		/* device name (console, lnxx) */
	short ut_pid ;			/* process id */
	short ut_type ; 		/* type of entry */
	struct exit_status
	  {
	    short e_termination ;	/* Process termination status */
	    short e_exit ;		/* Process exit status */
	  }
	ut_exit ;			/* The exit status of a process
					 * marked as DEAD_PROCESS.
					 */
	time_t ut_time ;		/* time entry was made */
  } ;

/*	Definitions for ut_type						*/

#define	EMPTY		0
#define	RUN_LVL		1
#define	BOOT_TIME	2
#define	OLD_TIME	3
#define	NEW_TIME	4
#define	INIT_PROCESS	5	/* Process spawned by "init" */
#define	LOGIN_PROCESS	6	/* A "getty" process waiting for login */
#define	USER_PROCESS	7	/* A user process */
#define	DEAD_PROCESS	8
#define	ACCOUNTING	9

#define	UTMAXTYPE	ACCOUNTING	/* Largest legal value of ut_type */

/*	Special strings or formats used in the "ut_line" field when	*/
/*	accounting for something other than a process.			*/
/*	No string for the ut_line field can be more than 11 chars +	*/
/*	a NULL in length.						*/

#define	RUNLVL_MSG	"run-level %c"
#define	BOOT_MSG	"system boot"
#define	OTIME_MSG	"old time"
#define	NTIME_MSG	"new time"
-------------

	And you just read all the entries that have a ut_type equal to
USER_PROCESS. This does not exist on BSD systems, however, I once wrote
a kill idle program on a V8 System, you don't really need to know the
person's root pid, just read /etc/utmp and get his ut_line, check the
access times to determine if he is idle, and if so, set sg.sg_ispeed
and sg.sg_ospeed to 0 (from sgtty.h, or, I beleive stty.h on BSD), then
stty(3) or ioctl(2) his terminal with this (as long as you have modem
control) and he will be logged off. Also, it's nice to warn the person
that he will be nuked if he remains idle for another few minutes, then
nuke him.
-- 
                                        =======
     Mikel Manitius                   ==----=====    AT&T
     (305) 869-2462 RNX: 755         ==------=====   Information Systems 
     ...{akguc|ihnp4}!codas!mikel    ===----======   SDSS Regional Support
     ...attmail!mmanitius             ===========    Altamonte Springs, FL
     My opinions are my own.            =======



More information about the Comp.unix mailing list