From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.redhat.com (mail.redhat.com [199.183.24.239]) by listman.redhat.com (Postfix) with ESMTP id 8DA742EFD8 for ; Wed, 24 Jan 2001 12:40:31 -0500 (EST) Received: (from mail@localhost) by mail.redhat.com (8.11.0/8.8.7) id f0OHeHs10616 for axp-list@listman.redhat.com; Wed, 24 Jan 2001 12:40:17 -0500 Received: from ztxmail05.ztx.compaq.com (ztxmail05.ztx.compaq.com [161.114.1.209]) by mail.redhat.com (8.11.0/8.8.7) with ESMTP id f0OHeHd10612 for ; Wed, 24 Jan 2001 12:40:17 -0500 Received: by ztxmail05.ztx.compaq.com (Postfix, from userid 12345) id D7262A47; Wed, 24 Jan 2001 11:40:23 -0600 (CST) Received: from ives.lkg.dec.com (ives.lkg.dec.com [16.24.240.4]) by ztxmail05.ztx.compaq.com (Postfix) with ESMTP id C961A899; Wed, 24 Jan 2001 11:39:51 -0600 (CST) Received: by ives.lkg.dec.com (8.8.8/1.1.19.2/18May00-1129AM) id MAA04474; Wed, 24 Jan 2001 12:39:45 -0500 (EST) From: Bharadwaj Yadavalli Message-Id: <200101241739.MAA04474@ives.lkg.dec.com> Subject: Re: /proc/PID/stat To: axp-list@redhat.com Date: Wed, 24 Jan 2001 12:39:45 -0500 (EST) Cc: gatgul@voicenet.com In-Reply-To: <3A6E2BC2.E513FF26@voicenet.com> from "Uncle George" at Jan 23, 2001 08:11:30 PM X-Mailer: ELM [version 2.5 PL1] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0beta4 Precedence: bulk Reply-To: axp-list@redhat.com List-Id: Linux and Red Hat on Alpha processors From : Uncle George Date : Tue Jan 23 20:11:30 2001 Is there a pgm that will interpret all the fields that are printed by cat /proc/PID/stat ( or statm, or any of the info on a per process basis ) See if the following simple function and the associated structure that I put together sometime ago while checking out some threads- related stuff on Linux/Alpha is of use. Also note that the format characters as given in the man page for proc are not all correct on Alpha. I just when to the sources to get them right (RTFS?:-)) typedef struct statstruct_proc { int pid; /** The process id. **/ char exName [_POSIX_PATH_MAX]; /** The filename of the executable **/ char state; /** 1 **/ /** R is running, S is sleeping, D is sleeping in an uninterruptible wait, Z is zombie, T is traced or stopped **/ unsigned euid, /** effective user id **/ egid; /** effective group id */ int ppid; /** The pid of the parent. **/ int pgrp; /** The pgrp of the process. **/ int session; /** The session id of the process. **/ int tty; /** The tty the process uses **/ int tpgid; /** (too long) **/ unsigned int flags; /** The flags of the process. **/ unsigned int minflt; /** The number of minor faults **/ unsigned int cminflt; /** The number of minor faults with childs **/ unsigned int majflt; /** The number of major faults **/ unsigned int cmajflt; /** The number of major faults with childs **/ int utime; /** user mode jiffies **/ int stime; /** kernel mode jiffies **/ int cutime; /** user mode jiffies with childs **/ int cstime; /** kernel mode jiffies with childs **/ int counter; /** process's next timeslice **/ int priority; /** the standard nice value, plus fifteen **/ unsigned int timeout; /** The time in jiffies of the next timeout **/ unsigned int itrealvalue; /** The time before the next SIGALRM is sent to the process **/ int starttime; /** 20 **/ /** Time the process started after system boot **/ unsigned int vsize; /** Virtual memory size **/ unsigned int rss; /** Resident Set Size **/ unsigned int rlim; /** Current limit in bytes on the rss **/ unsigned int startcode; /** The address above which program text can run **/ unsigned int endcode; /** The address below which program text can run **/ unsigned int startstack; /** The address of the start of the stack **/ unsigned int kstkesp; /** The current value of ESP **/ unsigned int kstkeip; /** The current value of EIP **/ int signal; /** The bitmap of pending signals **/ int blocked; /** 30 **/ /** The bitmap of blocked signals **/ int sigignore; /** The bitmap of ignored signals **/ int sigcatch; /** The bitmap of catched signals **/ unsigned int wchan; /** 33 **/ /** (too long) **/ int sched, /** scheduler **/ sched_priority; /** scheduler priority **/ } procinfo; int get_proc_info(pid_t pid, procinfo * pinfo) { char szFileName [_POSIX_PATH_MAX], szStatStr [2048], *s, *t; FILE *fp; struct stat st; if (NULL == pinfo) { errno = EINVAL; return -1; } sprintf (szFileName, "/proc/%u/stat", (unsigned) pid); if (-1 == access (szFileName, R_OK)) { return (pinfo->pid = -1); } /** if **/ if (-1 != stat (szFileName, &st)) { pinfo->euid = st.st_uid; pinfo->egid = st.st_gid; } else { pinfo->euid = pinfo->egid = -1; } if ((fp = fopen (szFileName, "r")) == NULL) { return (pinfo->pid = -1); } /** IF_NULL **/ if ((s = fgets (szStatStr, 2048, fp)) == NULL) { fclose (fp); return (pinfo->pid = -1); } /** pid **/ sscanf (szStatStr, "%u", &(pinfo->pid)); s = strchr (szStatStr, '(') + 1; t = strchr (szStatStr, ')'); strncpy (pinfo->exName, s, t - s); pinfo->exName [t - s] = '\0'; sscanf (t + 2, "%c %d %d %d %d %d %u %u %u %u %u %d %d %d %d %d %d %u %u %d %u %u %u %u %u %u %u %u %d %d %d %d %u", /* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33*/ &(pinfo->state), &(pinfo->ppid), &(pinfo->pgrp), &(pinfo->session), &(pinfo->tty), &(pinfo->tpgid), &(pinfo->flags), &(pinfo->minflt), &(pinfo->cminflt), &(pinfo->majflt), &(pinfo->cmajflt), &(pinfo->utime), &(pinfo->stime), &(pinfo->cutime), &(pinfo->cstime), &(pinfo->counter), &(pinfo->priority), &(pinfo->timeout), &(pinfo->itrealvalue), &(pinfo->starttime), &(pinfo->vsize), &(pinfo->rss), &(pinfo->rlim), &(pinfo->startcode), &(pinfo->endcode), &(pinfo->startstack), &(pinfo->kstkesp), &(pinfo->kstkeip), &(pinfo->signal), &(pinfo->blocked), &(pinfo->sigignore), &(pinfo->sigcatch), &(pinfo->wchan)); fclose (fp); return 0; } Bharadwaj