1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-13 11:15:27 +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
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.
<para /></listitem>
</varlistentry>

View File

@ -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,

View File

@ -64,6 +64,7 @@
#include <sys/time.h>
#include <regex.h>
#include <pwd.h>
/******************************************
* 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;