1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-04 21:18:33 +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 f6b38df642
commit 6c04ba542b
4 changed files with 25 additions and 1 deletions

View File

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

@ -2578,6 +2578,7 @@ static void process_parse_stat(struct process *process)
int endl;
int nice_val;
char *lparen, *rparen;
struct stat process_stat;
snprintf(filename, sizeof(filename), PROCFS_TEMPLATE, process->pid);
@ -2587,6 +2588,10 @@ static void process_parse_stat(struct process *process)
return;
}
if (fstat(ps, &process_stat) != 0)
return;
process->uid=process_stat.st_uid;
/* Mark process as up-to-date. */
process->time_stamp = g_time;

View File

@ -484,6 +484,16 @@ static void print_top_time(struct text_object *obj, char *p, int p_max_size)
free(timeval);
}
static void print_top_user(struct text_object *obj, char *p, int p_max_size)
{
struct top_data *td = (struct top_data *)obj->data.opaque;
if (!td || !td->list || !td->list[td->num])
return;
snprintf(p, p_max_size, "%.8s", getpwuid(td->list[td->num]->uid)->pw_name);
}
#define PRINT_TOP_GENERATOR(name, width, fmt, field) \
static void print_top_##name(struct text_object *obj, char *p, int p_max_size) \
{ \
@ -504,6 +514,7 @@ static void print_top_##name(struct text_object *obj, char *p, int p_max_size) \
PRINT_TOP_GENERATOR(cpu, 7, "%6.2f", amount)
PRINT_TOP_GENERATOR(pid, 6, "%5i", pid)
PRINT_TOP_GENERATOR(uid, 6, "%5i", uid)
PRINT_TOP_HR_GENERATOR(mem_res, rss, 1)
PRINT_TOP_HR_GENERATOR(mem_vsize, vsize, 1)
#ifdef BUILD_IOSTATS
@ -577,6 +588,10 @@ int parse_top_args(const char *s, const char *arg, struct text_object *obj)
obj->callbacks.print = &print_top_mem_res;
} else if (strcmp(buf, "mem_vsize") == EQUAL) {
obj->callbacks.print = &print_top_mem_vsize;
} else if (strcmp(buf, "uid") == EQUAL) {
obj->callbacks.print = &print_top_uid;
} else if (strcmp(buf, "user") == EQUAL) {
obj->callbacks.print = &print_top_user;
#ifdef BUILD_IOSTATS
} else if (strcmp(buf, "io_read") == EQUAL) {
obj->callbacks.print = &print_top_read_bytes;

View File

@ -64,6 +64,7 @@
#include <sys/time.h>
#include <regex.h>
#include <pwd.h>
/******************************************
@ -84,6 +85,8 @@ enum top_field {
TOP_TIME,
TOP_MEM_RES,
TOP_MEM_VSIZE,
TOP_UID,
TOP_USER,
TOP_READ_BYTES,
TOP_WRITE_BYTES,
TOP_IO_PERC
@ -99,6 +102,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;