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
19 extern procps_status_t * procps_scan(int save_user_arg0)
23 static procps_status_t ret_status;
29 procps_status_t curstatus;
35 dir = opendir("/proc");
37 error_msg_and_die("Can't open /proc");
40 if((entry = readdir(dir)) == NULL) {
46 if (!(*name >= '0' && *name <= '9'))
49 memset(&curstatus, 0, sizeof(procps_status_t));
53 sprintf(status, "/proc/%d/stat", pid);
54 if((fp = fopen(status, "r")) == NULL)
56 if(fstat(fileno(fp), &sb))
58 my_getpwuid(curstatus.user, sb.st_uid);
59 name = fgets(buf, sizeof(buf), fp);
63 name = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */
64 if(name == 0 || name[1] != ' ')
67 sscanf(buf, "%*s (%15c", curstatus.short_cmd);
70 "%*s %*s %*s %*s " /* pgrp, session, tty, tpgid */
71 "%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
72 #ifdef FEATURE_CPU_USAGE_PERCENTAGE
77 "%*s %*s %*s " /* cutime, cstime, priority */
79 "%*s %*s %*s " /* timeout, it_real_value, start_time */
82 curstatus.state, &curstatus.ppid,
83 #ifdef FEATURE_CPU_USAGE_PERCENTAGE
84 &curstatus.utime, &curstatus.stime,
88 #ifdef FEATURE_CPU_USAGE_PERCENTAGE
95 if (curstatus.rss == 0 && curstatus.state[0] != 'Z')
96 curstatus.state[1] = 'W';
98 curstatus.state[1] = ' ';
100 curstatus.state[2] = '<';
101 else if (tasknice > 0)
102 curstatus.state[2] = 'N';
104 curstatus.state[2] = ' ';
106 curstatus.rss <<= (PAGE_SHIFT - 10); /* 2**10 = 1kb */
108 sprintf(status, "/proc/%d/cmdline", pid);
110 if((fp = fopen(status, "r")) == NULL)
112 if((n=fread(buf, 1, sizeof(buf)-1, fp)) > 0) {
117 if(((unsigned char)*name) < ' ')
124 curstatus.cmd = strdup(buf);
125 /* if NULL it work true also */
129 return memcpy(&ret_status, &curstatus, sizeof(procps_status_t));
136 c-file-style: "linux"