android o ps命令,解析ANDROID ps命令执行后各项参数的含义

static int ps_line(int pid, int tid, char *namefilter)

{

char statline[1024];

char cmdline[1024];

char user[32];

struct stat stats;

int fd, r;

char *ptr, *name, *state;

int ppid, tty;

unsigned wchan, rss, vss, eip;

unsigned utime, stime;

int prio, nice, rtprio, sched;

struct passwd *pw;

sprintf(statline, "/proc/%d", pid);

stat(statline, &stats);

if(tid) {

sprintf(statline, "/proc/%d/task/%d/stat", pid, tid);

cmdline[0] = 0;

} else {

sprintf(statline, "/proc/%d/stat", pid);

sprintf(cmdline, "/proc/%d/cmdline", pid);

fd = open(cmdline, O_RDONLY);

if(fd == 0) {

r = 0;

} else {

r = read(fd, cmdline, 1023);

close(fd);

if(r 

}

cmdline[r] = 0;

}

fd = open(statline, O_RDONLY);

if(fd == 0) return -1;

r = read(fd, statline, 1023);

close(fd);

if(r 

statline[r] = 0;

ptr = statline;

nexttok(&ptr); // skip pid

ptr++;          // skip "("

name = ptr;

ptr = strrchr(ptr, ')'); // Skip to *last* occurence of ')',

*ptr++ = '\0';           // and null-terminate name.

ptr++;          // skip " "

state = nexttok(&ptr);

ppid = atoi(nexttok(&ptr));

nexttok(&ptr); // pgrp

nexttok(&ptr); // sid

tty = atoi(nexttok(&ptr));

nexttok(&ptr); // tpgid

nexttok(&ptr); // flags

nexttok(&ptr); // minflt

nexttok(&ptr); // cminflt

nexttok(&ptr); // majflt

nexttok(&ptr); // cmajflt

#if 1

utime = atoi(nexttok(&ptr));

stime = atoi(nexttok(&ptr));

#else

nexttok(&ptr); // utime

nexttok(&ptr); // stime

#endif

nexttok(&ptr); // cutime

nexttok(&ptr); // cstime

prio = atoi(nexttok(&ptr));

nice = atoi(nexttok(&ptr));

nexttok(&ptr); // threads

nexttok(&ptr); // itrealvalue

nexttok(&ptr); // starttime

vss = strtoul(nexttok(&ptr), 0, 10); // vsize

rss = strtoul(nexttok(&ptr), 0, 10); // rss

nexttok(&ptr); // rlim

nexttok(&ptr); // startcode

nexttok(&ptr); // endcode

nexttok(&ptr); // startstack

nexttok(&ptr); // kstkesp

eip = strtoul(nexttok(&ptr), 0, 10); // kstkeip

nexttok(&ptr); // signal

nexttok(&ptr); // blocked

nexttok(&ptr); // sigignore

nexttok(&ptr); // sigcatch

wchan = strtoul(nexttok(&ptr), 0, 10); // wchan

nexttok(&ptr); // nswap

nexttok(&ptr); // cnswap

nexttok(&ptr); // exit signal

nexttok(&ptr); // processor

rtprio = atoi(nexttok(&ptr)); // rt_priority

sched = atoi(nexttok(&ptr)); // scheduling policy

tty = atoi(nexttok(&ptr));

if(tid != 0) {

ppid = pid;

pid = tid;

}

pw = getpwuid(stats.st_uid);

if(pw == 0) {

sprintf(user,"%d",(int)stats.st_uid);

} else {

strcpy(user,pw->pw_name);

}

if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) {

printf("%-8s %-5d %-5d %-5d %-5d", user, pid, ppid, vss / 1024, rss * 4);

if(display_flags&SHOW_PRIO)

printf(" %-5d %-5d %-5d %-5d", prio, nice, rtprio, sched);

printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name);

if(display_flags&SHOW_TIME)

printf(" (u:%d, s:%d)", utime, stime);

printf("\n");

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值