1 /* vi: set sw=4 ts=4: */
3 * Mini ps implementation(s) for busybox
5 * Copyright (C) 1999-2004 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 int terminal_width = TERMINAL_WIDTH;
52 if(is_flask_enabled() && argv[1] && !strcmp(argv[1], "-c") )
56 get_terminal_width_height(0, &terminal_width, NULL);
62 printf(" PID Context Stat Command\n");
65 printf(" PID Uid VmSize Stat Command\n");
67 while ((p = procps_scan(1, use_selinux, &sid)) != 0) {
69 while ((p = procps_scan(1)) != 0) {
71 char *namecmd = p->cmd;
78 if(security_sid_to_context(sid, (security_context_t)&sbuf, &len))
79 strcpy(sbuf, "unknown");
81 len = printf("%5d %-32s %s ", p->pid, sbuf, p->state);
86 len = printf("%5d %-8s %s ", p->pid, p->user, p->state);
88 len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state);
89 i = terminal_width-len;
91 if(namecmd != 0 && namecmd[0] != 0) {
94 if(strlen(namecmd) > i)
96 printf("%s\n", namecmd);
98 namecmd = p->short_cmd;
101 if(strlen(namecmd) > (i-2))
103 printf("[%s]\n", namecmd);