//proc/9744$ cat status
Name: gedit /*进程的程序名*/
State: S (sleeping) /*进程的状态信息,具体参见http://blog.chinaunix.net/u2/73528/showart_1106510.html*/
Tgid: 9744 /*线程组号*/
Pid: 9744 /*进程pid*/
PPid: 7672 /*父进程的pid*/
TracerPid: 0 /*跟踪进程的pid*/
Uid: 1000 1000 1000 1000 /*uid euid suid fsuid*/
Gid: 1000 1000 1000 1000 /*gid egid sgid fsgid*/
FDSize: 256 /*文件描述符的最大个数,file->fds*/
Groups: 0 4 20 24 25 29 30 44 46 107 109 115 124 1000 /*启动该进程的用户所属的组的id*/
VmPeak: 60184 kB /*进程地址空间的大小*/
VmSize: 60180 kB /*进程虚拟地址空间的大小reserved_vm:进程在预留或特殊的内存间的物理页*/
VmLck: 0 kB /*进程已经锁住的物理内存的大小.锁住的物理内存不能交换到硬盘*/
VmHWM: 18020 kB /*文件内存映射和匿名内存映射的大小*/
VmRSS: 18020 kB /*应用程序正在使用的物理内存的大小,就是用ps命令的参数rss的值 (rss)*/
VmData: 12240 kB /*程序数据段的大小(所占虚拟内存的大小),存放初始化了的数据*/
VmStk: 84 kB /*进程在用户态的栈的大小*/
VmExe: 576 kB /*程序所拥有的可执行虚拟内存的大小,代码段,不包括任务使用的库 */
VmLib: 21072 kB /*被映像到任务的虚拟内存空间的库的大小*/
VmPTE: 56 kB /*该进程的所有页表的大小*/
Threads: 1 /*共享使用该信号描述符的任务的个数*/
SigQ: 0/8183 /*待处理信号的个数/目前最大可以处理的信号的个数*/
SigPnd: 0000000000000000 /*屏蔽位,存储了该线程的待处理信号*/
ShdPnd: 0000000000000000 /*屏蔽位,存储了该线程组的待处理信号*/
SigBlk: 0000000000000000 /*存放被阻塞的信号*/
SigIgn: 0000000000001000 /*存放被忽略的信号*/
SigCgt: 0000000180000000 /*存放被俘获到的信号*/
CapInh: 0000000000000000 /*能被当前进程执行的程序的继承的能力*/
CapPrm: 0000000000000000 /*进程能够使用的能力,可以包含CapEff中没有的能力,这些能力是被进程自己临时放弃的*/
CapEff: 0000000000000000 /*是CapPrm的一个子集,进程放弃没有必要的能力有利于提高安全性*/
Cpus_allowed: 01 /*可以执行该进程的CPU掩码集*/
Mems_allowed: 1 /**/
voluntary_ctxt_switches: 1241 /*进程主动切换的次数*/
nonvoluntary_ctxt_switches: 717 /*进程被动切换的次数*/
/proc/PID/stat各个字段的描述
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 {
1、int pid; /** The process id. **/
2、char exName [_POSIX_PATH_MAX]; /** The filename of the executable **/
3、char state; /** 1 **/ /** R is running, S is sleeping,
D is sleeping in an uninterruptible wait,
Z is zombie, T is traced or stopped **/
4、unsigned euid, /** effective user id **/
egid; /** effective group id */
5、int ppid; /** The pid of the parent. **/
6、int pgrp; /** The pgrp of the process. process group**/
7、int session; /** The session id of the process. **/
8、int tty; /** The tty the process uses **/
9、int tpgid; /** (too long) **/
10、unsigned intflags; /** The flags of the process. **/
11、unsigned intminflt; /** The number of minor faults **/
12、unsigned intcminflt; /** The number of minor faults with childs **/
13、unsigned intmajflt; /** The number of major faults **/
14、unsigned int cmajflt; /** The number of major faults with childs **/
15、int utime; /** user mode jiffies **/
16、int stime; /** kernel mode jiffies **/
17、int cutime; /** user mode jiffies with childs **/
18、int cstime; /** kernel mode jiffies with childs **/
19、int counter; /** process's next timeslice **/
20、int priority; /** the standard nice value, plus fifteen **/
21、unsigned int timeout; /** The time in jiffies of the next timeout **/
22、unsigned int itrealvalue; /** The time before the next SIGALRM is sent to the process **/
23、int starttime; /** 20 **/ /** Time the process started after system boot **/
24、unsigned int vsize; /** Virtual memory size **/
25、unsigned int rss; /** Resident Set Size **/
26、unsigned int rlim; /** Current limit in bytes on the rss **/
27、unsigned int startcode; /** The address above which program text can run **/
28、unsigned intendcode; /** The address below which program text can run **/
29、unsigned int startstack; /** The address of the start of the stack **/
30、unsigned int kstkesp; /** The current value of ESP **/
31、unsigned int kstkeip; /** The current value of EIP **/
32、intsignal; /** The bitmap of pending signals **/
33、int blocked; /** 30 **/ /** The bitmap of blocked signals **/
34、int sigignore; /** The bitmap of ignored signals **/
35、int sigcatch; /** The bitmap of catched signals **/
36、unsigned int wchan; /** 33 **/ /** (too long) **/
37、intsched, /** 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] = '';
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;
}