Mirror of git://git.busybox.net/busybox with our patches on top
Source
"%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright 1998 by Albert Cahalan; all rights reserved.
* Copyright (C) 2002 by Vladimir Oleynik <dzo@simtreas.ru>
* GNU Library General Public License Version 2, or any later version
*
*/
extern procps_status_t * procps_scan(int save_user_arg0)
{
static DIR *dir;
struct dirent *entry;
static procps_status_t ret_status;
char *name;
int n;
char status[32];
char buf[1024];
FILE *fp;
procps_status_t curstatus;
int pid;
long tasknice;
struct stat sb;
if (!dir) {
dir = opendir("/proc");
if(!dir)
bb_error_msg_and_die("Can't open /proc");
}
for(;;) {
if((entry = readdir(dir)) == NULL) {
closedir(dir);
dir = 0;
return 0;
}
name = entry->d_name;
if (!(*name >= '0' && *name <= '9'))
continue;
memset(&curstatus, 0, sizeof(procps_status_t));
pid = atoi(name);
curstatus.pid = pid;
sprintf(status, "/proc/%d", pid);
if(stat(status, &sb))
continue;
my_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user));
sprintf(status, "/proc/%d/stat", pid);
if((fp = fopen(status, "r")) == NULL)
continue;
name = fgets(buf, sizeof(buf), fp);
fclose(fp);