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
11 #if ! defined CONFIG_FEATURE_USE_DEVPS_PATCH
20 extern procps_status_t * procps_scan(int save_user_arg0)
24 static procps_status_t ret_status;
30 procps_status_t curstatus;
36 dir = opendir("/proc");
38 error_msg_and_die("Can't open /proc");
41 if((entry = readdir(dir)) == NULL) {
47 if (!(*name >= '0' && *name <= '9'))
50 memset(&curstatus, 0, sizeof(procps_status_t));
54 sprintf(status, "/proc/%d/stat", pid);
55 if((fp = fopen(status, "r")) == NULL)
57 if(fstat(fileno(fp), &sb))
59 my_getpwuid(curstatus.user, sb.st_uid);
60 name = fgets(buf, sizeof(buf), fp);
64 name = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */
65 if(name == 0 || name[1] != ' ')
68 sscanf(buf, "%*s (%15c", curstatus.short_cmd);
71 "%*s %*s %*s %*s " /* pgrp, session, tty, tpgid */
72 "%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
73 #ifdef FEATURE_CPU_USAGE_PERCENTAGE
78 "%*s %*s %*s " /* cutime, cstime, priority */
80 "%*s %*s %*s " /* timeout, it_real_value, start_time */
83 curstatus.state, &curstatus.ppid,
84 #ifdef FEATURE_CPU_USAGE_PERCENTAGE
85 &curstatus.utime, &curstatus.stime,
89 #ifdef FEATURE_CPU_USAGE_PERCENTAGE
96 if (curstatus.rss == 0 && curstatus.state[0] != 'Z')
97 curstatus.state[1] = 'W';
99 curstatus.state[1] = ' ';
101 curstatus.state[2] = '<';
102 else if (tasknice > 0)
103 curstatus.state[2] = 'N';
105 curstatus.state[2] = ' ';
107 curstatus.rss <<= (PAGE_SHIFT - 10); /* 2**10 = 1kb */
109 sprintf(status, "/proc/%d/cmdline", pid);
111 if((fp = fopen(status, "r")) == NULL)
113 if((n=fread(buf, 1, sizeof(buf)-1, fp)) > 0) {
118 if(((unsigned char)*name) < ' ')
125 curstatus.cmd = strdup(buf);
126 /* if NULL it work true also */
130 return memcpy(&ret_status, &curstatus, sizeof(procps_status_t));
134 #endif /* CONFIG_FEATURE_USE_DEVPS_PATCH. Else this file is empty */
139 c-file-style: "linux"