1 --- busybox-1.20.1/procps/ps.c
2 +++ busybox-1.20.1-ps/procps/ps.c
4 /* Absolute maximum on output line length */
5 enum { MAX_WIDTH = 2*1024 };
7 +#if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG
8 +static long get_uptime(void)
11 + struct sysinfo info;
12 + if (sysinfo(&info) < 0)
18 + if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0)
19 + bb_perror_msg_and_die("can't read %s", "/proc/uptime");
20 + buf[sizeof(buf)-1] = '\0';
21 + sscanf(buf, "%l", &uptime);
25 + if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
34 #include <sys/times.h> /* for times() */
35 @@ -197,8 +222,6 @@ static inline unsigned get_HZ_by_waiting
37 static unsigned get_kernel_HZ(void)
40 - struct sysinfo info;
44 @@ -208,12 +231,7 @@ static unsigned get_kernel_HZ(void)
45 if (kernel_HZ == (unsigned)-1)
46 kernel_HZ = get_HZ_by_waiting();
48 - //if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0)
49 - // bb_perror_msg_and_die("can't read %s", "/proc/uptime");
50 - //buf[sizeof(buf)-1] = '\0';
51 - ///sscanf(buf, "%llu", &seconds_since_boot);
53 - seconds_since_boot = info.uptime;
54 + seconds_since_boot = get_uptime();
58 @@ -635,7 +653,7 @@ int ps_main(int argc UNUSED_PARAM, char
60 #if ENABLE_FEATURE_PS_LONG
62 - struct sysinfo info;
66 /* If we support any options, parse argv */
67 @@ -695,7 +713,7 @@ int ps_main(int argc UNUSED_PARAM, char
68 puts("S UID PID PPID VSZ RSS TTY STIME TIME CMD");
69 #if ENABLE_FEATURE_PS_LONG
72 + uptime = get_uptime();
76 @@ -727,7 +745,7 @@ int ps_main(int argc UNUSED_PARAM, char
77 char tty[2 * sizeof(int)*3 + 2];
79 unsigned sut = (p->stime + p->utime) / 100;
80 - unsigned elapsed = info.uptime - (p->start_time / 100);
81 + unsigned elapsed = uptime - (p->start_time / 100);
82 time_t start = now - elapsed;
83 struct tm *tm = localtime(&start);