aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
Diffstat (limited to 'procps')
-rw-r--r--procps/nmeter.c200
-rw-r--r--procps/renice.c13
2 files changed, 97 insertions, 116 deletions
diff --git a/procps/nmeter.c b/procps/nmeter.c
index 5d5b83b8d..33de3790f 100644
--- a/procps/nmeter.c
+++ b/procps/nmeter.c
@@ -21,7 +21,7 @@
21//usage:#define nmeter_full_usage "\n\n" 21//usage:#define nmeter_full_usage "\n\n"
22//usage: "Monitor system in real time" 22//usage: "Monitor system in real time"
23//usage: "\n" 23//usage: "\n"
24//usage: "\n -d MSEC Milliseconds between updates (default:1000)" 24//usage: "\n -d MSEC Milliseconds between updates, default:1000, none:-1"
25//usage: "\n" 25//usage: "\n"
26//usage: "\nFormat specifiers:" 26//usage: "\nFormat specifiers:"
27//usage: "\n %Nc or %[cN] CPU. N - bar size (default:10)" 27//usage: "\n %Nc or %[cN] CPU. N - bar size (default:10)"
@@ -83,10 +83,10 @@ struct globals {
83 smallint is26; 83 smallint is26;
84 // 1 if sample delay is not an integer fraction of a second 84 // 1 if sample delay is not an integer fraction of a second
85 smallint need_seconds; 85 smallint need_seconds;
86 char final_char;
86 char *cur_outbuf; 87 char *cur_outbuf;
87 const char *final_str;
88 int delta; 88 int delta;
89 int deltanz; 89 unsigned deltanz;
90 struct timeval tv; 90 struct timeval tv;
91#define first_proc_file proc_stat 91#define first_proc_file proc_stat
92 proc_file proc_stat; // Must match the order of proc_name's! 92 proc_file proc_stat; // Must match the order of proc_name's!
@@ -101,9 +101,6 @@ struct globals {
101#define is26 (G.is26 ) 101#define is26 (G.is26 )
102#define need_seconds (G.need_seconds ) 102#define need_seconds (G.need_seconds )
103#define cur_outbuf (G.cur_outbuf ) 103#define cur_outbuf (G.cur_outbuf )
104#define final_str (G.final_str )
105#define delta (G.delta )
106#define deltanz (G.deltanz )
107#define tv (G.tv ) 104#define tv (G.tv )
108#define proc_stat (G.proc_stat ) 105#define proc_stat (G.proc_stat )
109#define proc_loadavg (G.proc_loadavg ) 106#define proc_loadavg (G.proc_loadavg )
@@ -114,8 +111,8 @@ struct globals {
114#define INIT_G() do { \ 111#define INIT_G() do { \
115 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 112 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
116 cur_outbuf = outbuf; \ 113 cur_outbuf = outbuf; \
117 final_str = "\n"; \ 114 G.final_char = '\n'; \
118 deltanz = delta = 1000000; \ 115 G.deltanz = G.delta = 1000000; \
119} while (0) 116} while (0)
120 117
121// We depend on this being a char[], not char* - we take sizeof() of it 118// We depend on this being a char[], not char* - we take sizeof() of it
@@ -142,11 +139,11 @@ static void print_outbuf(void)
142 139
143static void put(const char *s) 140static void put(const char *s)
144{ 141{
145 int sz = strlen(s); 142 char *p = cur_outbuf;
146 if (sz > outbuf + sizeof(outbuf) - cur_outbuf) 143 int sz = outbuf + sizeof(outbuf) - p;
147 sz = outbuf + sizeof(outbuf) - cur_outbuf; 144 while (*s && --sz >= 0)
148 memcpy(cur_outbuf, s, sz); 145 *p++ = *s++;
149 cur_outbuf += sz; 146 cur_outbuf = p;
150} 147}
151 148
152static void put_c(char c) 149static void put_c(char c)
@@ -208,65 +205,50 @@ static ullong read_after_slash(const char *p)
208 return strtoull(p+1, NULL, 10); 205 return strtoull(p+1, NULL, 10);
209} 206}
210 207
211enum conv_type { conv_decimal, conv_slash }; 208enum conv_type {
209 conv_decimal = 0,
210 conv_slash = 1
211};
212 212
213// Reads decimal values from line. Values start after key, for example: 213// Reads decimal values from line. Values start after key, for example:
214// "cpu 649369 0 341297 4336769..." - key is "cpu" here. 214// "cpu 649369 0 341297 4336769..." - key is "cpu" here.
215// Values are stored in vec[]. arg_ptr has list of positions 215// Values are stored in vec[].
216// we are interested in: for example: 1,2,5 - we want 1st, 2nd and 5th value. 216// posbits is a bit lit of positions we are interested in.
217static int vrdval(const char* p, const char* key, 217// for example: 00100110 - we want 1st, 2nd and 5th value.
218 enum conv_type conv, ullong *vec, va_list arg_ptr) 218// posbits.bit0 encodes conversion type.
219static int rdval(const char* p, const char* key, ullong *vec, long posbits)
219{ 220{
220 int indexline; 221 unsigned curpos;
221 int indexnext;
222 222
223 p = strstr(p, key); 223 p = strstr(p, key);
224 if (!p) return 1; 224 if (!p) return 1;
225 225
226 p += strlen(key); 226 p += strlen(key);
227 indexline = 1; 227 curpos = 1 << 1;
228 indexnext = va_arg(arg_ptr, int);
229 while (1) { 228 while (1) {
230 while (*p == ' ' || *p == '\t') p++; 229 while (*p == ' ' || *p == '\t') p++;
231 if (*p == '\n' || *p == '\0') break; 230 if (*p == '\n' || *p == '\0') break;
232 231
233 if (indexline == indexnext) { // read this value 232 if (curpos & posbits) { // read this value
234 *vec++ = conv==conv_decimal ? 233 *vec++ = (posbits & 1) == conv_decimal ?
235 strtoull(p, NULL, 10) : 234 strtoull(p, NULL, 10) :
236 read_after_slash(p); 235 read_after_slash(p);
237 indexnext = va_arg(arg_ptr, int); 236 posbits -= curpos;
237 if (posbits <= 1)
238 return 0;
238 } 239 }
239 while (*p > ' ') p++; // skip over value 240 while (*p > ' ') // skip over the value
240 indexline++; 241 p++;
242 curpos <<= 1;
241 } 243 }
242 return 0; 244 return 0;
243} 245}
244 246
245// Parses files with lines like "cpu0 21727 0 15718 1813856 9461 10485 0 0":
246// rdval(file_contents, "string_to_find", result_vector, value#, value#...)
247// value# start with 1
248static int rdval(const char* p, const char* key, ullong *vec, ...)
249{
250 va_list arg_ptr;
251 int result;
252
253 va_start(arg_ptr, vec);
254 result = vrdval(p, key, conv_decimal, vec, arg_ptr);
255 va_end(arg_ptr);
256
257 return result;
258}
259
260// Parses files with lines like "... ... ... 3/148 ...." 247// Parses files with lines like "... ... ... 3/148 ...."
261static int rdval_loadavg(const char* p, ullong *vec, ...) 248static int rdval_loadavg(const char* p, ullong *vec, long posbits)
262{ 249{
263 va_list arg_ptr;
264 int result; 250 int result;
265 251 result = rdval(p, "", vec, posbits | conv_slash);
266 va_start(arg_ptr, vec);
267 result = vrdval(p, "", conv_slash, vec, arg_ptr);
268 va_end(arg_ptr);
269
270 return result; 252 return result;
271} 253}
272 254
@@ -337,7 +319,6 @@ static void scale(ullong ul)
337 put(buf); 319 put(buf);
338} 320}
339 321
340
341#define S_STAT(a) \ 322#define S_STAT(a) \
342typedef struct a { \ 323typedef struct a { \
343 struct s_stat *next; \ 324 struct s_stat *next; \
@@ -359,21 +340,12 @@ static s_stat* init_literal(void)
359 return (s_stat*)s; 340 return (s_stat*)s;
360} 341}
361 342
362static s_stat* init_delay(const char *param)
363{
364 delta = strtoul(param, NULL, 0) * 1000; /* param can be "" */
365 deltanz = delta > 0 ? delta : 1;
366 need_seconds = (1000000%deltanz) != 0;
367 return NULL;
368}
369
370static s_stat* init_cr(const char *param UNUSED_PARAM) 343static s_stat* init_cr(const char *param UNUSED_PARAM)
371{ 344{
372 final_str = "\r"; 345 G.final_char = '\r';
373 return (s_stat*)0; 346 return NULL;
374} 347}
375 348
376
377// user nice system idle iowait irq softirq (last 3 only in 2.6) 349// user nice system idle iowait irq softirq (last 3 only in 2.6)
378//cpu 649369 0 341297 4336769 11640 7122 1183 350//cpu 649369 0 341297 4336769 11640 7122 1183
379//cpuN 649369 0 341297 4336769 11640 7122 1183 351//cpuN 649369 0 341297 4336769 11640 7122 1183
@@ -381,10 +353,9 @@ enum { CPU_FIELDCNT = 7 };
381S_STAT(cpu_stat) 353S_STAT(cpu_stat)
382 ullong old[CPU_FIELDCNT]; 354 ullong old[CPU_FIELDCNT];
383 int bar_sz; 355 int bar_sz;
384 char *bar; 356 char bar[1];
385S_STAT_END(cpu_stat) 357S_STAT_END(cpu_stat)
386 358
387
388static void FAST_FUNC collect_cpu(cpu_stat *s) 359static void FAST_FUNC collect_cpu(cpu_stat *s)
389{ 360{
390 ullong data[CPU_FIELDCNT] = { 0, 0, 0, 0, 0, 0, 0 }; 361 ullong data[CPU_FIELDCNT] = { 0, 0, 0, 0, 0, 0, 0 };
@@ -395,7 +366,15 @@ static void FAST_FUNC collect_cpu(cpu_stat *s)
395 char *bar = s->bar; 366 char *bar = s->bar;
396 int i; 367 int i;
397 368
398 if (rdval(get_file(&proc_stat), "cpu ", data, 1, 2, 3, 4, 5, 6, 7)) { 369 if (rdval(get_file(&proc_stat), "cpu ", data, 0
370 | (1 << 1)
371 | (1 << 2)
372 | (1 << 3)
373 | (1 << 4)
374 | (1 << 5)
375 | (1 << 6)
376 | (1 << 7))
377 ) {
399 put_question_marks(bar_sz); 378 put_question_marks(bar_sz);
400 return; 379 return;
401 } 380 }
@@ -438,22 +417,20 @@ static void FAST_FUNC collect_cpu(cpu_stat *s)
438 put(s->bar); 417 put(s->bar);
439} 418}
440 419
441
442static s_stat* init_cpu(const char *param) 420static s_stat* init_cpu(const char *param)
443{ 421{
444 int sz; 422 int sz;
445 cpu_stat *s = xzalloc(sizeof(*s)); 423 cpu_stat *s;
446 s->collect = collect_cpu;
447 sz = strtoul(param, NULL, 0); /* param can be "" */ 424 sz = strtoul(param, NULL, 0); /* param can be "" */
448 if (sz < 10) sz = 10; 425 if (sz < 10) sz = 10;
449 if (sz > 1000) sz = 1000; 426 if (sz > 1000) sz = 1000;
450 s->bar = xzalloc(sz+1); 427 s = xzalloc(sizeof(*s) + sz);
451 /*s->bar[sz] = '\0'; - xzalloc did it */ 428 /*s->bar[sz] = '\0'; - xzalloc did it */
452 s->bar_sz = sz; 429 s->bar_sz = sz;
430 s->collect = collect_cpu;
453 return (s_stat*)s; 431 return (s_stat*)s;
454} 432}
455 433
456
457S_STAT(int_stat) 434S_STAT(int_stat)
458 ullong old; 435 ullong old;
459 int no; 436 int no;
@@ -464,7 +441,7 @@ static void FAST_FUNC collect_int(int_stat *s)
464 ullong data[1]; 441 ullong data[1];
465 ullong old; 442 ullong old;
466 443
467 if (rdval(get_file(&proc_stat), "intr", data, s->no)) { 444 if (rdval(get_file(&proc_stat), "intr", data, 1 << s->no)) {
468 put_question_marks(4); 445 put_question_marks(4);
469 return; 446 return;
470 } 447 }
@@ -488,7 +465,6 @@ static s_stat* init_int(const char *param)
488 return (s_stat*)s; 465 return (s_stat*)s;
489} 466}
490 467
491
492S_STAT(ctx_stat) 468S_STAT(ctx_stat)
493 ullong old; 469 ullong old;
494S_STAT_END(ctx_stat) 470S_STAT_END(ctx_stat)
@@ -498,7 +474,7 @@ static void FAST_FUNC collect_ctx(ctx_stat *s)
498 ullong data[1]; 474 ullong data[1];
499 ullong old; 475 ullong old;
500 476
501 if (rdval(get_file(&proc_stat), "ctxt", data, 1)) { 477 if (rdval(get_file(&proc_stat), "ctxt", data, 1 << 1)) {
502 put_question_marks(4); 478 put_question_marks(4);
503 return; 479 return;
504 } 480 }
@@ -516,7 +492,6 @@ static s_stat* init_ctx(const char *param UNUSED_PARAM)
516 return (s_stat*)s; 492 return (s_stat*)s;
517} 493}
518 494
519
520S_STAT(blk_stat) 495S_STAT(blk_stat)
521 const char* lookfor; 496 const char* lookfor;
522 ullong old[2]; 497 ullong old[2];
@@ -530,7 +505,10 @@ static void FAST_FUNC collect_blk(blk_stat *s)
530 if (is26) { 505 if (is26) {
531 i = rdval_diskstats(get_file(&proc_diskstats), data); 506 i = rdval_diskstats(get_file(&proc_diskstats), data);
532 } else { 507 } else {
533 i = rdval(get_file(&proc_stat), s->lookfor, data, 1, 2); 508 i = rdval(get_file(&proc_stat), s->lookfor, data, 0
509 | (1 << 1)
510 | (1 << 2)
511 );
534 // Linux 2.4 reports bio in Kbytes, convert to sectors: 512 // Linux 2.4 reports bio in Kbytes, convert to sectors:
535 data[0] *= 2; 513 data[0] *= 2;
536 data[1] *= 2; 514 data[1] *= 2;
@@ -559,7 +537,6 @@ static s_stat* init_blk(const char *param UNUSED_PARAM)
559 return (s_stat*)s; 537 return (s_stat*)s;
560} 538}
561 539
562
563S_STAT(fork_stat) 540S_STAT(fork_stat)
564 ullong old; 541 ullong old;
565S_STAT_END(fork_stat) 542S_STAT_END(fork_stat)
@@ -568,7 +545,7 @@ static void FAST_FUNC collect_thread_nr(fork_stat *s UNUSED_PARAM)
568{ 545{
569 ullong data[1]; 546 ullong data[1];
570 547
571 if (rdval_loadavg(get_file(&proc_loadavg), data, 4)) { 548 if (rdval_loadavg(get_file(&proc_loadavg), data, 1 << 4)) {
572 put_question_marks(4); 549 put_question_marks(4);
573 return; 550 return;
574 } 551 }
@@ -580,7 +557,7 @@ static void FAST_FUNC collect_fork(fork_stat *s)
580 ullong data[1]; 557 ullong data[1];
581 ullong old; 558 ullong old;
582 559
583 if (rdval(get_file(&proc_stat), "processes", data, 1)) { 560 if (rdval(get_file(&proc_stat), "processes", data, 1 << 1)) {
584 put_question_marks(4); 561 put_question_marks(4);
585 return; 562 return;
586 } 563 }
@@ -602,7 +579,6 @@ static s_stat* init_fork(const char *param)
602 return (s_stat*)s; 579 return (s_stat*)s;
603} 580}
604 581
605
606S_STAT(if_stat) 582S_STAT(if_stat)
607 ullong old[4]; 583 ullong old[4];
608 const char *device; 584 const char *device;
@@ -614,7 +590,12 @@ static void FAST_FUNC collect_if(if_stat *s)
614 ullong data[4]; 590 ullong data[4];
615 int i; 591 int i;
616 592
617 if (rdval(get_file(&proc_net_dev), s->device_colon, data, 1, 3, 9, 11)) { 593 if (rdval(get_file(&proc_net_dev), s->device_colon, data, 0
594 | (1 << 1)
595 | (1 << 3)
596 | (1 << 9)
597 | (1 << 11))
598 ) {
618 put_question_marks(10); 599 put_question_marks(10);
619 return; 600 return;
620 } 601 }
@@ -644,7 +625,6 @@ static s_stat* init_if(const char *device)
644 return (s_stat*)s; 625 return (s_stat*)s;
645} 626}
646 627
647
648S_STAT(mem_stat) 628S_STAT(mem_stat)
649 char opt; 629 char opt;
650S_STAT_END(mem_stat) 630S_STAT_END(mem_stat)
@@ -692,7 +672,7 @@ static void FAST_FUNC collect_mem(mem_stat *s)
692 ullong m_cached = 0; 672 ullong m_cached = 0;
693 ullong m_slab = 0; 673 ullong m_slab = 0;
694 674
695 if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1)) { 675 if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1 << 1)) {
696 put_question_marks(4); 676 put_question_marks(4);
697 return; 677 return;
698 } 678 }
@@ -701,10 +681,10 @@ static void FAST_FUNC collect_mem(mem_stat *s)
701 return; 681 return;
702 } 682 }
703 683
704 if (rdval(proc_meminfo.file, "MemFree:", &m_free , 1) 684 if (rdval(proc_meminfo.file, "MemFree:", &m_free , 1 << 1)
705 || rdval(proc_meminfo.file, "Buffers:", &m_bufs , 1) 685 || rdval(proc_meminfo.file, "Buffers:", &m_bufs , 1 << 1)
706 || rdval(proc_meminfo.file, "Cached:", &m_cached, 1) 686 || rdval(proc_meminfo.file, "Cached:", &m_cached, 1 << 1)
707 || rdval(proc_meminfo.file, "Slab:", &m_slab , 1) 687 || rdval(proc_meminfo.file, "Slab:", &m_slab , 1 << 1)
708 ) { 688 ) {
709 put_question_marks(4); 689 put_question_marks(4);
710 return; 690 return;
@@ -727,7 +707,6 @@ static s_stat* init_mem(const char *param)
727 return (s_stat*)s; 707 return (s_stat*)s;
728} 708}
729 709
730
731S_STAT(swp_stat) 710S_STAT(swp_stat)
732S_STAT_END(swp_stat) 711S_STAT_END(swp_stat)
733 712
@@ -735,8 +714,8 @@ static void FAST_FUNC collect_swp(swp_stat *s UNUSED_PARAM)
735{ 714{
736 ullong s_total[1]; 715 ullong s_total[1];
737 ullong s_free[1]; 716 ullong s_free[1];
738 if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1) 717 if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1 << 1)
739 || rdval(proc_meminfo.file, "SwapFree:" , s_free, 1) 718 || rdval(proc_meminfo.file, "SwapFree:" , s_free, 1 << 1)
740 ) { 719 ) {
741 put_question_marks(4); 720 put_question_marks(4);
742 return; 721 return;
@@ -751,7 +730,6 @@ static s_stat* init_swp(const char *param UNUSED_PARAM)
751 return (s_stat*)s; 730 return (s_stat*)s;
752} 731}
753 732
754
755S_STAT(fd_stat) 733S_STAT(fd_stat)
756S_STAT_END(fd_stat) 734S_STAT_END(fd_stat)
757 735
@@ -759,7 +737,10 @@ static void FAST_FUNC collect_fd(fd_stat *s UNUSED_PARAM)
759{ 737{
760 ullong data[2]; 738 ullong data[2];
761 739
762 if (rdval(get_file(&proc_sys_fs_filenr), "", data, 1, 2)) { 740 if (rdval(get_file(&proc_sys_fs_filenr), "", data, 0
741 | (1 << 1)
742 | (1 << 2))
743 ) {
763 put_question_marks(4); 744 put_question_marks(4);
764 return; 745 return;
765 } 746 }
@@ -774,17 +755,16 @@ static s_stat* init_fd(const char *param UNUSED_PARAM)
774 return (s_stat*)s; 755 return (s_stat*)s;
775} 756}
776 757
777
778S_STAT(time_stat) 758S_STAT(time_stat)
779 int prec; 759 unsigned prec;
780 int scale; 760 unsigned scale;
781S_STAT_END(time_stat) 761S_STAT_END(time_stat)
782 762
783static void FAST_FUNC collect_time(time_stat *s) 763static void FAST_FUNC collect_time(time_stat *s)
784{ 764{
785 char buf[sizeof("12:34:56.123456")]; 765 char buf[sizeof("12:34:56.123456")];
786 struct tm* tm; 766 struct tm* tm;
787 int us = tv.tv_usec + s->scale/2; 767 unsigned us = tv.tv_usec + s->scale/2;
788 time_t t = tv.tv_sec; 768 time_t t = tv.tv_sec;
789 769
790 if (us >= 1000000) { 770 if (us >= 1000000) {
@@ -825,11 +805,9 @@ static void FAST_FUNC collect_info(s_stat *s)
825 } 805 }
826} 806}
827 807
828
829typedef s_stat* init_func(const char *param); 808typedef s_stat* init_func(const char *param);
830 809
831// Deprecated %NNNd is to be removed, -d MSEC supersedes it 810static const char options[] ALIGN1 = "ncmsfixptbr";
832static const char options[] ALIGN1 = "ncmsfixptbdr";
833static init_func *const init_functions[] = { 811static init_func *const init_functions[] = {
834 init_if, 812 init_if,
835 init_cpu, 813 init_cpu,
@@ -841,7 +819,6 @@ static init_func *const init_functions[] = {
841 init_fork, 819 init_fork,
842 init_time, 820 init_time,
843 init_blk, 821 init_blk,
844 init_delay,
845 init_cr 822 init_cr
846}; 823};
847 824
@@ -864,8 +841,11 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv)
864 is26 = (strstr(buf, " 2.4.") == NULL); 841 is26 = (strstr(buf, " 2.4.") == NULL);
865 } 842 }
866 843
867 if (getopt32(argv, "d:", &opt_d)) 844 if (getopt32(argv, "d:", &opt_d)) {
868 init_delay(opt_d); 845 G.delta = xatoi(opt_d) * 1000;
846 G.deltanz = G.delta > 0 ? G.delta : 1;
847 need_seconds = (1000000 % G.deltanz) != 0;
848 }
869 argv += optind; 849 argv += optind;
870 850
871 if (!argv[0]) 851 if (!argv[0])
@@ -920,8 +900,8 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv)
920 last->next = s; 900 last->next = s;
921 last = s; 901 last = s;
922 } else { 902 } else {
923 // %NNNNd or %r option. remove it from string 903 // %r option. remove it from string
924 strcpy(prev + strlen(prev), cur); 904 overlapping_strcpy(prev + strlen(prev), cur);
925 cur = prev; 905 cur = prev;
926 } 906 }
927 } 907 }
@@ -939,15 +919,15 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv)
939 // Generate first samples but do not print them, they're bogus 919 // Generate first samples but do not print them, they're bogus
940 collect_info(first); 920 collect_info(first);
941 reset_outbuf(); 921 reset_outbuf();
942 if (delta >= 0) { 922 if (G.delta >= 0) {
943 gettimeofday(&tv, NULL); 923 gettimeofday(&tv, NULL);
944 usleep(delta > 1000000 ? 1000000 : delta - tv.tv_usec%deltanz); 924 usleep(G.delta > 1000000 ? 1000000 : G.delta - tv.tv_usec % G.deltanz);
945 } 925 }
946 926
947 while (1) { 927 while (1) {
948 gettimeofday(&tv, NULL); 928 gettimeofday(&tv, NULL);
949 collect_info(first); 929 collect_info(first);
950 put(final_str); 930 put_c(G.final_char);
951 print_outbuf(); 931 print_outbuf();
952 932
953 // Negative delta -> no usleep at all 933 // Negative delta -> no usleep at all
@@ -955,18 +935,18 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv)
955 // time resolution ;) 935 // time resolution ;)
956 // TODO: detect and avoid useless updates 936 // TODO: detect and avoid useless updates
957 // (like: nothing happens except time) 937 // (like: nothing happens except time)
958 if (delta >= 0) { 938 if (G.delta >= 0) {
959 int rem; 939 int rem;
960 // can be commented out, will sacrifice sleep time precision a bit 940 // can be commented out, will sacrifice sleep time precision a bit
961 gettimeofday(&tv, NULL); 941 gettimeofday(&tv, NULL);
962 if (need_seconds) 942 if (need_seconds)
963 rem = delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) % deltanz; 943 rem = G.delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) % G.deltanz;
964 else 944 else
965 rem = delta - tv.tv_usec%deltanz; 945 rem = G.delta - (unsigned)tv.tv_usec % G.deltanz;
966 // Sometimes kernel wakes us up just a tiny bit earlier than asked 946 // Sometimes kernel wakes us up just a tiny bit earlier than asked
967 // Do not go to very short sleep in this case 947 // Do not go to very short sleep in this case
968 if (rem < delta/128) { 948 if (rem < (unsigned)G.delta / 128) {
969 rem += delta; 949 rem += G.delta;
970 } 950 }
971 usleep(rem); 951 usleep(rem);
972 } 952 }
diff --git a/procps/renice.c b/procps/renice.c
index 77f400a1d..2b690e0ed 100644
--- a/procps/renice.c
+++ b/procps/renice.c
@@ -20,13 +20,14 @@
20 */ 20 */
21 21
22//usage:#define renice_trivial_usage 22//usage:#define renice_trivial_usage
23//usage: "{{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID...]" 23//usage: "[-n] PRIORITY [[-p | -g | -u] ID...]..."
24//usage:#define renice_full_usage "\n\n" 24//usage:#define renice_full_usage "\n\n"
25//usage: "Change scheduling priority for a running process\n" 25//usage: "Change scheduling priority of a running process\n"
26//usage: "\n -n Adjust current nice value (smaller is faster)" 26//usage: "\n -n Add PRIORITY to current nice value"
27//usage: "\n -p Process id(s) (default)" 27//usage: "\n Without -n, nice value is set to PRIORITY"
28//usage: "\n -g Process group id(s)" 28//usage: "\n -p Process ids (default)"
29//usage: "\n -u Process user name(s) and/or id(s)" 29//usage: "\n -g Process group ids"
30//usage: "\n -u Process user names"
30 31
31#include "libbb.h" 32#include "libbb.h"
32#include <sys/resource.h> 33#include <sys/resource.h>