1 /* vi: set sw=4 ts=4: */
5 * Copyright 1998 by Albert Cahalan; all rights reserved.
6 * Copyright (C) 2002 by Vladimir Oleynik <dzo@simtreas.ru>
7 * GNU Library General Public License Version 2, or any later version
19 extern procps_status_t * procps_scan(int save_user_arg0)
23 static procps_status_t ret_status;
29 procps_status_t curstatus;
35 dir = opendir("/proc");
37 bb_error_msg_and_die("Can't open /proc");
40 if((entry = readdir(dir)) == NULL) {
46 if (!(*name >= '0' && *name <= '9'))
49 memset(&curstatus, 0, sizeof(procps_status_t));
53 sprintf(status, "/proc/%d", pid);
56 bb_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user));
58 sprintf(status, "/proc/%d/stat", pid);
60 if((fp = fopen(status, "r")) == NULL)
62 name = fgets(buf, sizeof(buf), fp);
66 name = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */
67 if(name == 0 || name[1] != ' ')
70 sscanf(buf, "%*s (%15c", curstatus.short_cmd);
73 "%*s %*s %*s %*s " /* pgrp, session, tty, tpgid */
74 "%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
75 #ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
80 "%*s %*s %*s " /* cutime, cstime, priority */
82 "%*s %*s %*s " /* timeout, it_real_value, start_time */
85 curstatus.state, &curstatus.ppid,
86 #ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
87 &curstatus.utime, &curstatus.stime,
91 #ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
98 if (curstatus.rss == 0 && curstatus.state[0] != 'Z')
99 curstatus.state[1] = 'W';
101 curstatus.state[1] = ' ';
103 curstatus.state[2] = '<';
104 else if (tasknice > 0)
105 curstatus.state[2] = 'N';
107 curstatus.state[2] = ' ';
110 curstatus.rss <<= (PAGE_SHIFT - 10); /* 2**10 = 1kb */
112 curstatus.rss *= (getpagesize() >> 10); /* 2**10 = 1kb */
116 sprintf(status, "/proc/%d/cmdline", pid);
117 if((fp = fopen(status, "r")) == NULL)
119 if((n=fread(buf, 1, sizeof(buf)-1, fp)) > 0) {
124 if(((unsigned char)*name) < ' ')
131 curstatus.cmd = strdup(buf);
132 /* if NULL it work true also */
136 return memcpy(&ret_status, &curstatus, sizeof(procps_status_t));
143 c-file-style: "linux"