1 /* vi: set sw=4 ts=4: */
3 * Mini ps implementation(s) for busybox
5 * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
6 * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 * Place, Suite 330, Boston, MA 02111-1307 USA
32 #include <sys/ioctl.h>
35 static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */
39 extern int ps_main(int argc, char **argv)
43 #ifdef CONFIG_FEATURE_AUTOWIDTH
44 struct winsize win = { 0, 0, 0, 0 };
45 int terminal_width = TERMINAL_WIDTH;
47 #define terminal_width TERMINAL_WIDTH
51 #ifdef CONFIG_FEATURE_AUTOWIDTH
52 ioctl(fileno(stdout), TIOCGWINSZ, &win);
54 terminal_width = win.ws_col - 1;
57 printf(" PID Uid VmSize Stat Command\n");
58 while ((p = procps_scan(1)) != 0) {
59 char *namecmd = p->cmd;
62 len = printf("%5d %-8s %s ", p->pid, p->user, p->state);
64 len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state);
65 i = terminal_width-len;
67 if(namecmd != 0 && namecmd[0] != 0) {
70 if(strlen(namecmd) > i)
72 printf("%s\n", namecmd);
74 namecmd = p->short_cmd;
77 if(strlen(namecmd) > (i-2))
79 printf("[%s]\n", namecmd);