diff options
author | Benoit Dejean <bdejean@gmail.com> | 2015-07-18 20:52:10 +0200 |
---|---|---|
committer | Benoit Dejean <bdejean@gmail.com> | 2015-07-18 20:52:10 +0200 |
commit | b44726069148a84dbce413064c60b6cc8263f68a (patch) | |
tree | d5ffe4a2876981b2ebef17613e71d1359744d561 | |
parent | 1dbe133a240bf13e31de81c3c33eeb7ece40659a (diff) | |
download | libgtop-b44726069148a84dbce413064c60b6cc8263f68a.tar.gz |
Turn the proclist example into a minimal `ps`.
-rw-r--r-- | examples/proclist.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/examples/proclist.c b/examples/proclist.c index db74e978..8ab0742d 100644 --- a/examples/proclist.c +++ b/examples/proclist.c @@ -1,5 +1,8 @@ #include <glibtop.h> #include <glibtop/proclist.h> +#include <glibtop/procstate.h> +#include <glibtop/proctime.h> +#include <glibtop/procuid.h> #include <glib.h> @@ -17,14 +20,28 @@ static void print_pids(guint64 which, guint64 arg) pids = glibtop_get_proclist(&buf, which, arg); - printf("glibtop_get_proclist(%#llx, %llu) -> %lu processes\n", - which, arg, (unsigned long)buf.number); - - for (i = 0; i < buf.number; ++i) - printf("%u ", pids[i]); - - putchar('\n'); - putchar('\n'); + for (i = 0; i < buf.number; ++i) { + glibtop_proc_time ptime; + glibtop_proc_uid puid; + glibtop_proc_state pstate; + + pid_t p = pids[i]; + + glibtop_get_proc_time(&ptime, p); + glibtop_get_proc_uid(&puid, p); + glibtop_get_proc_state(&pstate, p); + + /* almost equivalent to ps -x -o user,pid,time,usertime,systime,start,command */ + printf("%u pid=%u real=%.2f user=%.2f sys=%.2f start=%lu %s (%lx)\n", + puid.uid, + p, + (double)ptime.rtime / ptime.frequency, + (double)ptime.utime / ptime.frequency, + (double)ptime.stime / ptime.frequency, + (unsigned long)ptime.start_time, + pstate.cmd, + (long)ptime.flags); + } g_free(pids); } @@ -34,7 +51,6 @@ int main() { glibtop_init(); - print_pids(GLIBTOP_KERN_PROC_ALL, 0); print_pids(GLIBTOP_KERN_PROC_UID, getuid()); glibtop_close(); |