linux查看nec进程状态,【linux】 /proc/PID/stat

//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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The /proc/PID/stat file contains various statistics about the process with the specified PID. The file is a single line of text, with each field separated by a space. The fields in the file are as follows: 1. pid - process ID 2. comm - name of the command that started the process 3. state - current state of the process (e.g. running, sleeping, etc.) 4. ppid - parent process ID 5. pgrp - process group ID 6. session - session ID 7. tty_nr - controlling terminal of the process 8. tpgid - ID of the foreground process group of the controlling terminal 9. flags - process flags (e.g. whether it is being traced, etc.) 10. minflt - number of minor faults (i.e. page faults that could be resolved without disk IO) 11. cminflt - number of minor faults of child processes 12. majflt - number of major faults (i.e. page faults that required disk IO) 13. cmajflt - number of major faults of child processes 14. utime - amount of time the process has spent in user mode 15. stime - amount of time the process has spent in kernel mode 16. cutime - amount of time waited-for children have been in user mode 17. cstime - amount of time waited-for children have been in kernel mode 18. priority - priority of the process 19. nice - nice value of the process 20. num_threads - number of threads in the process 21. starttime - time the process started, in jiffies (1/100th of a second) 22. vsize - virtual memory size of the process 23. rss - resident set size of the process (i.e. amount of physical memory it is using) 24. rsslim - current limit on the resident set size 25. startcode - address of the start of the code segment 26. endcode - address of the end of the code segment 27. startstack - address of the start of the stack 28. kstkesp - current value of the stack pointer 29. kstkeip - current value of the instruction pointer 30. signal - bitmap of pending signals for the process 31. blocked - bitmap of blocked signals for the process 32. sigignore - bitmap of ignored signals for the process 33. sigcatch - bitmap of caught signals for the process 34. wchan - address of the kernel function the process is currently waiting in 35. nswap - number of pages swapped to disk 36. cnswap - number of pages swapped to disk of child processes 37. exit_signal - signal to be sent to the parent process when the process exits 38. processor - CPU the process last ran on 39. rt_priority - real-time priority of the process 40. policy - scheduling policy of the process Note: Some fields may be displayed as 0 if they are not applicable to the process or if they are not available. Also, the values for utime, stime, cutime, and cstime are given in clock ticks, which can be converted to seconds by dividing by the value of the system variable HZ (which is typically 100 on most systems).

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值