1 /* vi: set sw=4 ts=4: */
5 * Copyright 1998 by Albert Cahalan; all rights reserved.
6 * Copyright (C) 2002 by Vladimir Oleynik <dzo@simtreas.ru>
7 * GNU Library General Public License Version 2, or any later version
13 #if ! defined CONFIG_FEATURE_USE_DEVPS_PATCH
21 extern procps_status_t * procps_scan(int save_user_arg0)
25 static procps_status_t ret_status;
31 procps_status_t curstatus;
37 dir = opendir("/proc");
39 error_msg_and_die("Can't open /proc");
42 if((entry = readdir(dir)) == NULL) {
48 if (!(*name >= '0' && *name <= '9'))
51 memset(&curstatus, 0, sizeof(procps_status_t));
55 sprintf(status, "/proc/%d/stat", pid);
56 if((fp = fopen(status, "r")) == NULL)
58 if(fstat(fileno(fp), &sb))
60 my_getpwuid(curstatus.user, sb.st_uid);
61 name = fgets(buf, sizeof(buf), fp);
65 name = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */
66 if(name == 0 || name[1] != ' ')
69 sscanf(buf, "%*s (%15c", curstatus.short_cmd);
72 "%*s %*s %*s %*s " /* pgrp, session, tty, tpgid */
73 "%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
74 #ifdef FEATURE_CPU_USAGE_PERCENTAGE
79 "%*s %*s %*s " /* cutime, cstime, priority */
81 "%*s %*s %*s " /* timeout, it_real_value, start_time */
84 curstatus.state, &curstatus.ppid,
85 #ifdef FEATURE_CPU_USAGE_PERCENTAGE
86 &curstatus.utime, &curstatus.stime,
90 #ifdef FEATURE_CPU_USAGE_PERCENTAGE
97 if (curstatus.rss == 0 && curstatus.state[0] != 'Z')
98 curstatus.state[1] = 'W';
100 curstatus.state[1] = ' ';
102 curstatus.state[2] = '<';
103 else if (tasknice > 0)
104 curstatus.state[2] = 'N';
106 curstatus.state[2] = ' ';
108 curstatus.rss <<= (PAGE_SHIFT - 10); /* 2**10 = 1kb */
110 sprintf(status, "/proc/%d/cmdline", pid);
112 if((fp = fopen(status, "r")) == NULL)
114 if(fgets(buf, sizeof(buf), fp) != NULL) {
115 name = strchr(buf, '\n');
119 curstatus.cmd = strdup(buf);
120 /* if NULL it work true also */
124 return memcpy(&ret_status, &curstatus, sizeof(procps_status_t));
128 #endif /* CONFIG_FEATURE_USE_DEVPS_PATCH. Else this file is empty */
133 c-file-style: "linux"