diff options
Diffstat (limited to 'procps/ps.c')
-rw-r--r-- | procps/ps.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/procps/ps.c b/procps/ps.c index aa004aa22..dc6fda61d 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -69,6 +69,31 @@ | |||
69 | /* Absolute maximum on output line length */ | 69 | /* Absolute maximum on output line length */ |
70 | enum { MAX_WIDTH = 2*1024 }; | 70 | enum { MAX_WIDTH = 2*1024 }; |
71 | 71 | ||
72 | #if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG | ||
73 | static long get_uptime(void) | ||
74 | { | ||
75 | #ifdef __linux__ | ||
76 | struct sysinfo info; | ||
77 | if (sysinfo(&info) < 0) | ||
78 | return 0; | ||
79 | return info.uptime; | ||
80 | #elif 1 | ||
81 | char buf[64]; | ||
82 | long uptime; | ||
83 | if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0) | ||
84 | bb_perror_msg_and_die("can't read %s", "/proc/uptime"); | ||
85 | buf[sizeof(buf)-1] = '\0'; | ||
86 | sscanf(buf, "%l", &uptime); | ||
87 | return uptime; | ||
88 | #else | ||
89 | struct timespec ts; | ||
90 | if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) | ||
91 | return 0; | ||
92 | return ts.tv_sec; | ||
93 | #endif | ||
94 | } | ||
95 | #endif | ||
96 | |||
72 | #if ENABLE_DESKTOP | 97 | #if ENABLE_DESKTOP |
73 | 98 | ||
74 | #include <sys/times.h> /* for times() */ | 99 | #include <sys/times.h> /* for times() */ |
@@ -197,8 +222,6 @@ static inline unsigned get_HZ_by_waiting(void) | |||
197 | 222 | ||
198 | static unsigned get_kernel_HZ(void) | 223 | static unsigned get_kernel_HZ(void) |
199 | { | 224 | { |
200 | //char buf[64]; | ||
201 | struct sysinfo info; | ||
202 | 225 | ||
203 | if (kernel_HZ) | 226 | if (kernel_HZ) |
204 | return kernel_HZ; | 227 | return kernel_HZ; |
@@ -208,12 +231,7 @@ static unsigned get_kernel_HZ(void) | |||
208 | if (kernel_HZ == (unsigned)-1) | 231 | if (kernel_HZ == (unsigned)-1) |
209 | kernel_HZ = get_HZ_by_waiting(); | 232 | kernel_HZ = get_HZ_by_waiting(); |
210 | 233 | ||
211 | //if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0) | 234 | seconds_since_boot = get_uptime(); |
212 | // bb_perror_msg_and_die("can't read %s", "/proc/uptime"); | ||
213 | //buf[sizeof(buf)-1] = '\0'; | ||
214 | ///sscanf(buf, "%llu", &seconds_since_boot); | ||
215 | sysinfo(&info); | ||
216 | seconds_since_boot = info.uptime; | ||
217 | 235 | ||
218 | return kernel_HZ; | 236 | return kernel_HZ; |
219 | } | 237 | } |
@@ -645,7 +663,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
645 | }; | 663 | }; |
646 | #if ENABLE_FEATURE_PS_LONG | 664 | #if ENABLE_FEATURE_PS_LONG |
647 | time_t now = now; | 665 | time_t now = now; |
648 | struct sysinfo info; | 666 | long uptime; |
649 | #endif | 667 | #endif |
650 | int opts = 0; | 668 | int opts = 0; |
651 | /* If we support any options, parse argv */ | 669 | /* If we support any options, parse argv */ |
@@ -705,7 +723,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
705 | puts("S UID PID PPID VSZ RSS TTY STIME TIME CMD"); | 723 | puts("S UID PID PPID VSZ RSS TTY STIME TIME CMD"); |
706 | #if ENABLE_FEATURE_PS_LONG | 724 | #if ENABLE_FEATURE_PS_LONG |
707 | now = time(NULL); | 725 | now = time(NULL); |
708 | sysinfo(&info); | 726 | uptime = get_uptime(); |
709 | #endif | 727 | #endif |
710 | } | 728 | } |
711 | else { | 729 | else { |
@@ -737,7 +755,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
737 | char tty[2 * sizeof(int)*3 + 2]; | 755 | char tty[2 * sizeof(int)*3 + 2]; |
738 | char *endp; | 756 | char *endp; |
739 | unsigned sut = (p->stime + p->utime) / 100; | 757 | unsigned sut = (p->stime + p->utime) / 100; |
740 | unsigned elapsed = info.uptime - (p->start_time / 100); | 758 | unsigned elapsed = uptime - (p->start_time / 100); |
741 | time_t start = now - elapsed; | 759 | time_t start = now - elapsed; |
742 | struct tm *tm = localtime(&start); | 760 | struct tm *tm = localtime(&start); |
743 | 761 | ||