1 /* vi: set sw=4 ts=4: */
3 * Mini ps implementation(s) for busybox
5 * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/ioctl.h>
34 #include <fs_secure.h>
36 #include <flask_util.h> /* for is_flask_enabled() */
39 static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */
43 extern int ps_main(int argc, char **argv)
47 #ifdef CONFIG_FEATURE_AUTOWIDTH
48 struct winsize win = { 0, 0, 0, 0 };
49 int terminal_width = TERMINAL_WIDTH;
51 #define terminal_width TERMINAL_WIDTH
57 if(is_flask_enabled() && argv[1] && !strcmp(argv[1], "-c") )
62 #ifdef CONFIG_FEATURE_AUTOWIDTH
63 ioctl(fileno(stdout), TIOCGWINSZ, &win);
65 terminal_width = win.ws_col - 1;
70 printf(" PID Context Stat Command\n");
73 printf(" PID Uid VmSize Stat Command\n");
75 while ((p = procps_scan(1, use_selinux, &sid)) != 0) {
77 while ((p = procps_scan(1)) != 0) {
79 char *namecmd = p->cmd;
86 if(security_sid_to_context(sid, (security_context_t)&sbuf, &len))
87 strcpy(sbuf, "unknown");
89 len = printf("%5d %-32s %s ", p->pid, sbuf, p->state);
94 len = printf("%5d %-8s %s ", p->pid, p->user, p->state);
96 len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state);
97 i = terminal_width-len;
99 if(namecmd != 0 && namecmd[0] != 0) {
102 if(strlen(namecmd) > i)
104 printf("%s\n", namecmd);
106 namecmd = p->short_cmd;
109 if(strlen(namecmd) > (i-2))
111 printf("[%s]\n", namecmd);