aboutsummaryrefslogtreecommitdiff
path: root/procps/ps.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-08-10 00:36:07 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-08-10 00:36:07 +0200
commit83785f0ebcad58157bb7d866037664ab95563f48 (patch)
tree2638387178471d00ef96af990f7d34a395909598 /procps/ps.c
parentaa4e5092f58f5a11018e569aee9cf037daf8c5d6 (diff)
downloadbusybox-w32-1_20_2.tar.gz
busybox-w32-1_20_2.tar.bz2
busybox-w32-1_20_2.zip
Apply post-1.20.1 patches, bump version to 1.20.21_20_2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps/ps.c')
-rw-r--r--procps/ps.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/procps/ps.c b/procps/ps.c
index 4727b218b..3a5af7c18 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 */
70enum { MAX_WIDTH = 2*1024 }; 70enum { MAX_WIDTH = 2*1024 };
71 71
72#if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG
73static 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
198static unsigned get_kernel_HZ(void) 223static 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}
@@ -635,7 +653,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
635 }; 653 };
636#if ENABLE_FEATURE_PS_LONG 654#if ENABLE_FEATURE_PS_LONG
637 time_t now = now; 655 time_t now = now;
638 struct sysinfo info; 656 long uptime;
639#endif 657#endif
640 int opts = 0; 658 int opts = 0;
641 /* If we support any options, parse argv */ 659 /* If we support any options, parse argv */
@@ -695,7 +713,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
695 puts("S UID PID PPID VSZ RSS TTY STIME TIME CMD"); 713 puts("S UID PID PPID VSZ RSS TTY STIME TIME CMD");
696#if ENABLE_FEATURE_PS_LONG 714#if ENABLE_FEATURE_PS_LONG
697 now = time(NULL); 715 now = time(NULL);
698 sysinfo(&info); 716 uptime = get_uptime();
699#endif 717#endif
700 } 718 }
701 else { 719 else {
@@ -727,7 +745,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
727 char tty[2 * sizeof(int)*3 + 2]; 745 char tty[2 * sizeof(int)*3 + 2];
728 char *endp; 746 char *endp;
729 unsigned sut = (p->stime + p->utime) / 100; 747 unsigned sut = (p->stime + p->utime) / 100;
730 unsigned elapsed = info.uptime - (p->start_time / 100); 748 unsigned elapsed = uptime - (p->start_time / 100);
731 time_t start = now - elapsed; 749 time_t start = now - elapsed;
732 struct tm *tm = localtime(&start); 750 struct tm *tm = localtime(&start);
733 751