1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-14 19:39:47 +00:00

Add uid to "top" output (sf.net #3178916)

original patch submitted by Thomas Wiegner, I added support for printing of raw uids.
This commit is contained in:
Pavel Labath 2011-10-10 21:54:18 +02:00
parent 7ddec25d60
commit 8905dbb313
3 changed files with 26 additions and 3 deletions

View File

@ -3521,7 +3521,7 @@
(number) Basically, processes are ranked from highest to (number) Basically, processes are ranked from highest to
lowest in terms of cpu usage, which is what (num) lowest in terms of cpu usage, which is what (num)
represents. The types are: "name", "pid", "cpu", "mem", 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. "io_write". There can be a max of 10 processes listed.
<para /></listitem> <para /></listitem>
</varlistentry> </varlistentry>

View File

@ -210,6 +210,8 @@ static int process_parse_stat(struct process *process)
int nice_val; int nice_val;
char *lparen, *rparen; char *lparen, *rparen;
struct stat process_stat;
snprintf(filename, sizeof(filename), PROCFS_TEMPLATE, process->pid); snprintf(filename, sizeof(filename), PROCFS_TEMPLATE, process->pid);
ps = open(filename, O_RDONLY); ps = open(filename, O_RDONLY);
@ -218,6 +220,11 @@ static int process_parse_stat(struct process *process)
return 1; return 1;
} }
if (fstat(ps, &process_stat) != 0){
return 1;
}
process->uid=process_stat.st_uid;
/* Mark process as up-to-date. */ /* Mark process as up-to-date. */
process->time_stamp = g_time; 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; td->type = TOP_MEM_RES;
} else if (strcmp(buf, "mem_vsize") == EQUAL) { } else if (strcmp(buf, "mem_vsize") == EQUAL) {
td->type = TOP_MEM_VSIZE; 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 #ifdef IOSTATS
} else if (strcmp(buf, "io_read") == EQUAL) { } else if (strcmp(buf, "io_read") == EQUAL) {
td->type = TOP_READ_BYTES; td->type = TOP_READ_BYTES;
@ -875,10 +886,10 @@ int parse_top_args(const char *s, const char *arg, struct text_object *obj)
} else { } else {
NORM_ERR("invalid type arg for top"); NORM_ERR("invalid type arg for top");
#ifdef IOSTATS #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"); "io_read, io_write, io_perc");
#else /* IOSTATS */ #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 */ #endif /* IOSTATS */
free(td->s); free(td->s);
free(obj->data.opaque); 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, human_readable(needed[td->num]->vsize,
p, p_max_size); p, p_max_size);
break; 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 #ifdef IOSTATS
case TOP_READ_BYTES: case TOP_READ_BYTES:
human_readable(needed[td->num]->read_bytes / update_interval, human_readable(needed[td->num]->read_bytes / update_interval,

View File

@ -64,6 +64,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <regex.h> #include <regex.h>
#include <pwd.h>
/****************************************** /******************************************
* Defines * * Defines *
@ -87,6 +88,8 @@ enum top_field {
TOP_TIME, TOP_TIME,
TOP_MEM_RES, TOP_MEM_RES,
TOP_MEM_VSIZE, TOP_MEM_VSIZE,
TOP_UID,
TOP_USER,
#ifdef IOSTATS #ifdef IOSTATS
TOP_READ_BYTES, TOP_READ_BYTES,
TOP_WRITE_BYTES, TOP_WRITE_BYTES,
@ -104,6 +107,7 @@ struct process {
pid_t pid; pid_t pid;
char *name; char *name;
uid_t uid;
float amount; float amount;
// User and kernel times are in hundredths of seconds // User and kernel times are in hundredths of seconds
unsigned long user_time; unsigned long user_time;