added ps etimes, miscellaneous top enhancements

ps program
 . etimes added for ELAPSED expressed in seconds
 . time_t used in place of former unsigned long

top program
 . corrected scroll message bug when 'x' toggle on
 . fixed forest view potential missing libflags bug
 . improved 'k' default signal invocation logic
 . enhanced logic for %CPU maximums displayed
 . made signal handling more robust and efficient
This commit is contained in:
Craig Small
2011-09-12 22:18:23 +10:00
parent 73ade5e2cb
commit e4c45d6984
9 changed files with 118 additions and 39 deletions

View File

@@ -301,7 +301,7 @@ extern int prefer_bsd_defaults;
extern int running_only;
extern int screen_cols;
extern int screen_rows;
extern unsigned long seconds_since_boot;
extern time_t seconds_since_boot;
extern selection_node *selection_list;
extern unsigned simple_select;
extern sort_node *sort_list;

View File

@@ -489,10 +489,12 @@ not_root:
/* don't free the array because it takes time and ps will exit anyway */
}
#if 0
static int want_this_proc_nop(proc_t *dummy){
(void)dummy;
return 1;
}
#endif
/***** sorted or forest */
static void fancy_spew(void){

View File

@@ -69,7 +69,7 @@ unsigned personality = 0xffffffff;
int prefer_bsd_defaults = -1;
int screen_cols = -1;
int screen_rows = -1;
unsigned long seconds_since_boot = -1;
time_t seconds_since_boot = -1;
selection_node *selection_list = (selection_node *)0xdeadbeef;
unsigned simple_select = 0xffffffff;
sort_node *sort_list = (sort_node *)0xdeadbeef; /* ready-to-use sort list */

View File

@@ -76,7 +76,8 @@ static unsigned max_leftward = 0x12345678; /* space for LEFT stuff */
static int wide_signals; /* true if we have room */
static unsigned long seconds_since_1970;
static time_t seconds_since_1970;
static time_t time_of_boot;
static unsigned long page_shift;
@@ -277,6 +278,13 @@ STIME stime hms or md time format
***/
/* Source & destination are known. Return bytes or screen characters? */
//
// OldLinux FreeBSD HPUX
// ' ' ' ' ' ' ' '
// 'L' ' \_ ' '`-' ' '
// '+' ' \_ ' '|-' ' '
// '|' ' | ' '| ' ' '
//
static int forest_helper(char *restrict const outbuf){
char *p = forest_prefix;
char *q = outbuf;
@@ -430,6 +438,12 @@ static int pr_etime(char *restrict const outbuf, const proc_t *restrict const pp
return (int)(cp-outbuf);
}
/* elapsed wall clock time in seconds */
static int pr_etimes(char *restrict const outbuf, const proc_t *restrict const pp){
unsigned t = seconds_since_boot - (unsigned long)(pp->start_time / Hertz);
return snprintf(outbuf, COLWID, "%u", t);
}
/* "Processor utilisation for scheduling." --- we use %cpu w/o fraction */
static int pr_c(char *restrict const outbuf, const proc_t *restrict const pp){
unsigned long long total_time; /* jiffies used by this process */
@@ -950,7 +964,7 @@ static int pr_start(char *restrict const outbuf, const proc_t *restrict const pp
str = ctime(&t);
if(str[8]==' ') str[8]='0';
if(str[11]==' ') str[11]='0';
if((unsigned long)t+60*60*24 > seconds_since_1970)
if((unsigned long)t+60*60*24 > (unsigned long)seconds_since_1970)
return snprintf(outbuf, COLWID, "%8.8s", str+11);
return snprintf(outbuf, COLWID, " %6.6s", str+4);
}
@@ -1345,6 +1359,7 @@ static const format_struct format_array[] = {
{"environ","ENVIRONMENT",pr_nop, sr_nop, 11, ENV, LNx, PO|UNLIMITED},
{"esp", "ESP", pr_esp, sr_kstk_esp, 8, 0, LNX, TO|RIGHT},
{"etime", "ELAPSED", pr_etime, sr_nop, 11, 0, U98, ET|RIGHT}, /* was 7 wide */
{"etimes", "ELAPSED", pr_etimes, sr_nop, 7, 0, BSD, ET|RIGHT}, /* FreeBSD */
{"euid", "EUID", pr_euid, sr_euid, 5, 0, LNX, ET|RIGHT},
{"euser", "EUSER", pr_euser, sr_euser, 8, USR, LNX, ET|USER},
{"f", "F", pr_flag, sr_flags, 1, 0, XXX, ET|RIGHT}, /*flags*/

View File

@@ -617,6 +617,10 @@ static const char *parse_bsd_option(void){
trace("c true command name\n");
bsd_c_option = 1;
break;
// case 'd':
// trace("d FreeBSD-style tree\n");
// forest_type = 'f';
// break;
case 'e':
trace("e environment\n");
bsd_e_option = 1;

View File

@@ -1008,6 +1008,11 @@ elapsed time since the process was started,
in\ the form\ [[DD\-]hh:]mm:ss.
T}
etimes ELAPSED T{
elapsed time since the process was started,
in\ seconds.
T}
euid EUID T{
effective user\ ID (alias\ \fBuid\fR).
T}