aboutsummaryrefslogtreecommitdiff
path: root/procps/ps.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2002-12-05 07:24:08 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2002-12-05 07:24:08 +0000
commit49ec1a2dc6dfba670b3659286524fd5baf12e6fe (patch)
treef11db23c430298ac9da2f3de80ec6c86cc75be70 /procps/ps.c
parent8a500b97872ecfd6495c1cb6be98bc594627b311 (diff)
downloadbusybox-w32-49ec1a2dc6dfba670b3659286524fd5baf12e6fe.tar.gz
busybox-w32-49ec1a2dc6dfba670b3659286524fd5baf12e6fe.tar.bz2
busybox-w32-49ec1a2dc6dfba670b3659286524fd5baf12e6fe.zip
Kill CONFIG_FEATURE_USE_DEVPS_PATCH and the devps patch. I'm not
maintaining it anymore, and it is now terribly out of date. -Erik git-svn-id: svn://busybox.net/trunk/busybox@6101 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'procps/ps.c')
-rw-r--r--procps/ps.c104
1 files changed, 0 insertions, 104 deletions
diff --git a/procps/ps.c b/procps/ps.c
index cf2f2b0c4..5ccac7a95 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -20,12 +20,6 @@
20 * Place, Suite 330, Boston, MA 02111-1307 USA 20 * Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23/*
24 * This contains _two_ implementations of ps for Linux. One uses the
25 * traditional /proc virtual filesystem, and the other use the devps kernel
26 * driver (written by Erik Andersen to avoid using /proc thereby saving 100k+).
27 */
28
29#include <stdio.h> 23#include <stdio.h>
30#include <stdlib.h> 24#include <stdlib.h>
31#include <unistd.h> 25#include <unistd.h>
@@ -42,8 +36,6 @@ static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefo
42 36
43 37
44 38
45#if ! defined CONFIG_FEATURE_USE_DEVPS_PATCH
46
47extern int ps_main(int argc, char **argv) 39extern int ps_main(int argc, char **argv)
48{ 40{
49 procps_status_t * p; 41 procps_status_t * p;
@@ -91,99 +83,3 @@ extern int ps_main(int argc, char **argv)
91 return EXIT_SUCCESS; 83 return EXIT_SUCCESS;
92} 84}
93 85
94
95#else /* CONFIG_FEATURE_USE_DEVPS_PATCH */
96
97
98/* The following is the second ps implementation --
99 * this one uses the nifty new devps kernel device.
100 */
101
102#include <linux/devps.h> /* For Erik's nifty devps device driver */
103
104
105extern int ps_main(int argc, char **argv)
106{
107 char device[] = "/dev/ps";
108 int i, j, len, fd;
109 pid_t num_pids;
110 pid_t* pid_array = NULL;
111 struct pid_info info;
112 char uidName[9];
113#ifdef CONFIG_FEATURE_AUTOWIDTH
114 struct winsize win = { 0, 0, 0, 0 };
115 int terminal_width = TERMINAL_WIDTH;
116#else
117#define terminal_width TERMINAL_WIDTH
118#endif
119
120 if (argc > 1 && **(argv + 1) == '-')
121 show_usage();
122
123 /* open device */
124 fd = open(device, O_RDONLY);
125 if (fd < 0)
126 perror_msg_and_die( "open failed for `%s'", device);
127
128 /* Find out how many processes there are */
129 if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0)
130 perror_msg_and_die( "\nDEVPS_GET_PID_LIST");
131
132 /* Allocate some memory -- grab a few extras just in case
133 * some new processes start up while we wait. The kernel will
134 * just ignore any extras if we give it too many, and will trunc.
135 * the list if we give it too few. */
136 pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
137 pid_array[0] = num_pids+10;
138
139 /* Now grab the pid list */
140 if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0)
141 perror_msg_and_die("\nDEVPS_GET_PID_LIST");
142
143#ifdef CONFIG_FEATURE_AUTOWIDTH
144 ioctl(fileno(stdout), TIOCGWINSZ, &win);
145 if (win.ws_col > 0)
146 terminal_width = win.ws_col - 1;
147#endif
148
149 /* Print up a ps listing */
150 printf(" PID Uid Stat Command\n");
151
152 for (i=1; i<pid_array[0] ; i++) {
153 info.pid = pid_array[i];
154
155 if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
156 perror_msg_and_die("\nDEVPS_GET_PID_INFO");
157
158 /* Make some adjustments as needed */
159 my_getpwuid(uidName, info.euid);
160
161 if(p.vmsize == 0)
162 len = printf("%5d %-8s %c ", p.pid, uidName, p.state);
163 else
164 len = printf("%5d %-8s %6d %c ", p.pid, uidName, p.vmsize, p.state);
165 if (strlen(info.command_line) > 1) {
166 for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) {
167 if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') {
168 *(info.command_line+j) = ' ';
169 }
170 }
171 *(info.command_line+j) = '\0';
172 puts(info.command_line);
173 } else {
174 printf("[%s]\n", info.name);
175 }
176 }
177
178 /* Free memory */
179 free( pid_array);
180
181 /* close device */
182 if (close (fd) != 0)
183 perror_msg_and_die("close failed for `%s'", device);
184
185 exit (0);
186}
187
188#endif /* CONFIG_FEATURE_USE_DEVPS_PATCH */
189