diff --git a/doc/variables.xml b/doc/variables.xml index f570c85f..b4b48170 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -3521,7 +3521,7 @@ (number) Basically, processes are ranked from highest to lowest in terms of cpu usage, which is what (num) represents. The types are: "name", "pid", "cpu", "mem", - "mem_res", "mem_vsize", "time", "io_perc", "io_read" and + "mem_res", "mem_vsize", "time", "uid", "user", "io_perc", "io_read" and "io_write". There can be a max of 10 processes listed. diff --git a/src/top.c b/src/top.c index c99987d3..58400b01 100644 --- a/src/top.c +++ b/src/top.c @@ -210,6 +210,8 @@ static int process_parse_stat(struct process *process) int nice_val; char *lparen, *rparen; + struct stat process_stat; + snprintf(filename, sizeof(filename), PROCFS_TEMPLATE, process->pid); ps = open(filename, O_RDONLY); @@ -218,6 +220,11 @@ static int process_parse_stat(struct process *process) return 1; } + if (fstat(ps, &process_stat) != 0){ + return 1; + } + process->uid=process_stat.st_uid; + /* Mark process as up-to-date. */ process->time_stamp = g_time; @@ -864,6 +871,10 @@ int parse_top_args(const char *s, const char *arg, struct text_object *obj) td->type = TOP_MEM_RES; } else if (strcmp(buf, "mem_vsize") == EQUAL) { td->type = TOP_MEM_VSIZE; + } else if (strcmp(buf, "uid") == EQUAL) { + td->type = TOP_UID; + } else if (strcmp(buf, "user") == EQUAL) { + td->type = TOP_USER; #ifdef IOSTATS } else if (strcmp(buf, "io_read") == EQUAL) { td->type = TOP_READ_BYTES; @@ -875,10 +886,10 @@ int parse_top_args(const char *s, const char *arg, struct text_object *obj) } else { NORM_ERR("invalid type arg for top"); #ifdef IOSTATS - NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize, " + NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize, uid, user" "io_read, io_write, io_perc"); #else /* IOSTATS */ - NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize"); + NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize, uid, user"); #endif /* IOSTATS */ free(td->s); free(obj->data.opaque); @@ -1024,6 +1035,14 @@ void print_top(struct text_object *obj, char *p, int p_max_size) human_readable(needed[td->num]->vsize, p, p_max_size); break; + case TOP_UID: + snprintf(p, p_max_size, "%5d", needed[td->num]->uid); + break; + case TOP_USER: + width = MIN(p_max_size, 9); + snprintf(p, width, "%.8s", + getpwuid(needed[td->num]->uid)->pw_name); + break; #ifdef IOSTATS case TOP_READ_BYTES: human_readable(needed[td->num]->read_bytes / update_interval, diff --git a/src/top.h b/src/top.h index ccccfcd7..7a45e730 100644 --- a/src/top.h +++ b/src/top.h @@ -64,6 +64,7 @@ #include #include +#include /****************************************** * Defines * @@ -87,6 +88,8 @@ enum top_field { TOP_TIME, TOP_MEM_RES, TOP_MEM_VSIZE, + TOP_UID, + TOP_USER, #ifdef IOSTATS TOP_READ_BYTES, TOP_WRITE_BYTES, @@ -104,6 +107,7 @@ struct process { pid_t pid; char *name; + uid_t uid; float amount; // User and kernel times are in hundredths of seconds unsigned long user_time;