aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-19 14:46:14 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-19 14:46:14 +0000
commit516a0ca2dc92d9ea103535863102cc5425fe648e (patch)
tree4685bf59c11f898fad44f6e38cde3d16e43c723d /libbb
parentc34d35557b0eeb1971b65f7fb10b814295d61734 (diff)
downloadbusybox-w32-516a0ca2dc92d9ea103535863102cc5425fe648e.tar.gz
busybox-w32-516a0ca2dc92d9ea103535863102cc5425fe648e.tar.bz2
busybox-w32-516a0ca2dc92d9ea103535863102cc5425fe648e.zip
ps: add -o tty and -o rss support
1373 14 24 1411 583 busybox.t1/procps/ps.o 1462 14 24 1500 5dc busybox.t2/procps/ps.o
Diffstat (limited to 'libbb')
-rw-r--r--libbb/procps.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/libbb/procps.c b/libbb/procps.c
index c9dcfde0c..053f7d225 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -144,6 +144,9 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags)
144 144
145 if (flags & PSSCAN_STAT) { 145 if (flags & PSSCAN_STAT) {
146 char *cp; 146 char *cp;
147 unsigned long vsz, rss;
148 int tty;
149
147 /* see proc(5) for some details on this */ 150 /* see proc(5) for some details on this */
148 strcpy(filename_tail, "/stat"); 151 strcpy(filename_tail, "/stat");
149 n = read_to_buf(filename, buf); 152 n = read_to_buf(filename, buf);
@@ -158,33 +161,46 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags)
158 sscanf(buf, "%*s (%15c", sp->comm); 161 sscanf(buf, "%*s (%15c", sp->comm);
159 n = sscanf(cp+2, 162 n = sscanf(cp+2,
160 "%c %u " /* state, ppid */ 163 "%c %u " /* state, ppid */
161 "%u %u %*s %*s " /* pgid, sid, tty, tpgid */ 164 "%u %u %d %*s " /* pgid, sid, tty, tpgid */
162 "%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */ 165 "%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
163 "%lu %lu " /* utime, stime */ 166 "%lu %lu " /* utime, stime */
164 "%*s %*s %*s " /* cutime, cstime, priority */ 167 "%*s %*s %*s " /* cutime, cstime, priority */
165 "%ld " /* nice */ 168 "%ld " /* nice */
166 "%*s %*s %*s " /* timeout, it_real_value, start_time */ 169 "%*s %*s %*s " /* timeout, it_real_value, start_time */
167 "%lu ", /* vsize */ 170 "%lu " /* vsize */
171 "%lu " /* rss */
172 /* "%lu %lu %lu %lu %lu %lu " rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip */
173 /* "%u %u %u %u " signal, blocked, sigignore, sigcatch */
174 /* "%lu %lu %lu" wchan, nswap, cnswap */
175 ,
168 sp->state, &sp->ppid, 176 sp->state, &sp->ppid,
169 &sp->pgid, &sp->sid, 177 &sp->pgid, &sp->sid, &tty,
170 &sp->utime, &sp->stime, 178 &sp->utime, &sp->stime,
171 &tasknice, 179 &tasknice,
172 &sp->vsz); 180 &vsz,
173 if (n != 8) 181 &rss);
182 if (n != 10)
174 break; 183 break;
175 184
185 sp->tty_str[0] = '?';
186 /* sp->tty_str[1] = '\0'; - done by memset */
187 if (tty >= 0) /* tty field of "-1" means "no tty" */
188 snprintf(sp->tty_str, sizeof(sp->tty_str), "%u,%u",
189 (tty >> 8) & 0xfff, /* major */
190 (tty & 0xff) | ((tty >> 12) & 0xfff00));
176 if (sp->vsz == 0 && sp->state[0] != 'Z') 191 if (sp->vsz == 0 && sp->state[0] != 'Z')
177 sp->state[1] = 'W'; 192 sp->state[1] = 'W';
178 else 193 else
179 sp->state[1] = ' '; 194 sp->state[1] = ' ';
180 if (tasknice < 0) 195 if (tasknice < 0)
181 sp->state[2] = '<'; 196 sp->state[2] = '<';
182 else if (tasknice > 0) 197 else if (tasknice) /* > 0 */
183 sp->state[2] = 'N'; 198 sp->state[2] = 'N';
184 else 199 else
185 sp->state[2] = ' '; 200 sp->state[2] = ' ';
186 201
187 sp->vsz >>= 10; /* vsize is in bytes and we want kb */ 202 sp->vsz = vsz >> 10; /* vsize is in bytes and we want kb */
203 sp->rss = rss >> 10;
188 } 204 }
189 205
190 if (flags & PSSCAN_CMD) { 206 if (flags & PSSCAN_CMD) {