* /proc/PID/stat
@ 2001-01-24 1:11 Uncle George
2001-01-24 17:39 ` /proc/PID/stat Bharadwaj Yadavalli
0 siblings, 1 reply; 5+ messages in thread
From: Uncle George @ 2001-01-24 1:11 UTC (permalink / raw)
To: axp-list
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
)
/gat
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /proc/PID/stat
2001-01-24 1:11 /proc/PID/stat Uncle George
@ 2001-01-24 17:39 ` Bharadwaj Yadavalli
2001-01-24 19:02 ` /proc/PID/stat Uncle George
0 siblings, 1 reply; 5+ messages in thread
From: Bharadwaj Yadavalli @ 2001-01-24 17:39 UTC (permalink / raw)
To: axp-list; +Cc: gatgul
From : Uncle George <gatgul@voicenet.com>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /proc/PID/stat
2001-01-24 17:39 ` /proc/PID/stat Bharadwaj Yadavalli
@ 2001-01-24 19:02 ` Uncle George
2001-01-24 20:21 ` /proc/PID/stat Bharadwaj Yadavalli
2001-01-24 21:07 ` /proc/PID/stat Bharadwaj Yadavalli
0 siblings, 2 replies; 5+ messages in thread
From: Uncle George @ 2001-01-24 19:02 UTC (permalink / raw)
To: sby; +Cc: axp-list
Its interesting, but its not 64bit literate. For example the integer
stack pointer! The num of signals on alpha/linux is 64. Int will just
hold 32 of them ( & they certainly will not hold the SIG's 32 & 33 used
py the pthread system :-{ ).
What I wanted was a pgm that said
pc=0x45, ps=0x46908, sp=0x20012301234 .
So I guess that this does not exist.
Bharadwaj Yadavalli wrote:
>
> From : Uncle George <gatgul@voicenet.com>
> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /proc/PID/stat
2001-01-24 19:02 ` /proc/PID/stat Uncle George
@ 2001-01-24 20:21 ` Bharadwaj Yadavalli
2001-01-24 21:07 ` /proc/PID/stat Bharadwaj Yadavalli
1 sibling, 0 replies; 5+ messages in thread
From: Bharadwaj Yadavalli @ 2001-01-24 20:21 UTC (permalink / raw)
To: axp-list
From : Uncle George <gatgul@voicenet.com>
Date : Wed Jan 24 14:02:34 2001
Its interesting, but its not 64bit literate. For example the integer
stack pointer! The num of signals on alpha/linux is 64. Int will just
hold 32 of them ( & they certainly will not hold the SIG's 32 & 33 used
py the pthread system :-{ ).
What I wanted was a pgm that said
pc=0x45, ps=0x46908, sp=0x20012301234 .
So I guess that this does not exist.
I could have goofed up in specifying the types of some
values (I tried not to - but those not under my microscope
could have escaped). But if you look at the function get_stat()
in fs/proc/array.c of the linux sources (2.2.17 is what
I have), it should be very easy to figure out the format
of each of the fields; specifically look at the sprintf.
Bharadwaj
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /proc/PID/stat
2001-01-24 19:02 ` /proc/PID/stat Uncle George
2001-01-24 20:21 ` /proc/PID/stat Bharadwaj Yadavalli
@ 2001-01-24 21:07 ` Bharadwaj Yadavalli
1 sibling, 0 replies; 5+ messages in thread
From: Bharadwaj Yadavalli @ 2001-01-24 21:07 UTC (permalink / raw)
To: axp-list; +Cc: gatgul
From : Uncle George <gatgul@voicenet.com>
Date : Wed Jan 24 14:02:34 2001
Its interesting, but its not 64bit literate. For example the integer
stack pointer! The num of signals on alpha/linux is 64. Int will just
hold 32 of them ( & they certainly will not hold the SIG's 32 & 33 used
py the pthread system :-{ ).
What I wanted was a pgm that said
pc=0x45, ps=0x46908, sp=0x20012301234 .
Now I know what happened.... I sent out an old and incorrect
version. Here is the correct one. Apologies for the mistake.
Bharadwaj
typedef struct statstruct_proc {
int pid; /** %d The process id. **/
char exName [_POSIX_PATH_MAX]; /** %s The filename of the executable **/
char state; /** 1 **/ /** %c R is running, S is sleeping,
D is sleeping in an uninterruptible wait,
Z is zombie, T is traced or stopped **/
int euid, /** %d effective user id **/
egid; /** %d effective group id */
int ppid; /** %d The pid of the parent. **/
int pgrp; /** %d The pgrp of the process. **/
int session; /** %d The session id of the process. **/
unsigned long tty; /** %lu The tty the process uses **/
unsigned long tpgid; /** %lu **/
unsigned long flags; /** %lu The flags of the process. **/
unsigned long minflt; /** %lu The number of minor faults **/
unsigned long cminflt; /** %lu The number of minor faults with childs **/
unsigned long majflt; /** %lu The number of major faults **/
unsigned long cmajflt; /** %lu The number of major faults with childs **/
long utime; /** %ld user mode jiffies **/
long stime; /** %ld kernel mode jiffies **/
long cutime; /** %ld user mode jiffies with childs **/
long cstime; /** %ld kernel mode jiffies with childs **/
long counter; /** %ld process's next timeslice **/
long priority; /** %ld the standard nice value, plus fifteen **/
unsigned long timeout; /** %lu The time in jiffies of the next timeout **/
unsigned long itrealvalue; /** %lu The time before the next SIGALRM is sent to the process **/
long starttime; /** 20 **/ /** %ld Time the process started after system boot **/
unsigned long vsize; /** %lu Virtual memory size **/
unsigned long rss; /** %lu Resident Set Size **/
unsigned long rlim; /** %lu Current limit in bytes on the rss **/
unsigned long startcode; /** %lu The address above which program text can run **/
unsigned long endcode; /** %lu The address below which program text can run **/
unsigned long startstack; /** %lu The address of the start of the stack **/
unsigned long kstkesp; /** %lu The current value of ESP **/
unsigned long kstkeip; /** %lu The current value of EIP **/
unsigned long signal; /** %lu The bitmap of pending signals **/
unsigned long blocked; /** 30 **/ /** %lu The bitmap of blocked signals **/
unsigned long sigignore; /** %lu The bitmap of ignored signals **/
unsigned long sigcatch; /** %lu The bitmap of catched signals **/
unsigned long wchan; /** 33 **/ /** %lu **/
/* Ignoring 4 more fields that get printed on 2.2.17, for now */
} 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 (pinfo == NULL) {
errno = EINVAL;
return -1;
}
sprintf (szFileName, "/proc/%u/stat", (unsigned) pid);
if (access(szFileName, R_OK) == -1) {
return (pinfo->pid = -1);
}
if (stat(szFileName, &st) == -1) {
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 ((s = fgets (szStatStr, 2048, fp)) == NULL) {
fclose (fp);
return (pinfo->pid = -1);
}
sscanf (szStatStr, "%u", &(pinfo->pid));
s = strchr (szStatStr, '(') + 1;
t = strchr (szStatStr, ')');
strncpy (pinfo->exName, s, t - s);
pinfo->exName [t - s] = '\0';
/* out of fs/proc/array.c
sprintf(t + 2, "%c %d %d %d %d %d %lu %lu "
"%lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld "
"%lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %d %d");
*/
sscanf (t + 2, "%c %d %d %d %d %d %lu %lu %lu %lu "
/* 1 2 3 4 5 6 7 8 9 10 */
"%lu %lu %lu %ld %ld %ld %ld %lu %ld %lu "
/*11 12 13 14 15 16 17 18 19 20 */
"%lu %ld %lu %lu %lu %lu %lu %lu %lu %lu "
/*21 22 23 24 25 26 27 28 29 30 */
"%lu %lu %lu",
/*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;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-01-24 21:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-01-24 1:11 /proc/PID/stat Uncle George
2001-01-24 17:39 ` /proc/PID/stat Bharadwaj Yadavalli
2001-01-24 19:02 ` /proc/PID/stat Uncle George
2001-01-24 20:21 ` /proc/PID/stat Bharadwaj Yadavalli
2001-01-24 21:07 ` /proc/PID/stat Bharadwaj Yadavalli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox