Turn the proclist example into a minimal ps
.
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
#include <glibtop.h>
|
#include <glibtop.h>
|
||||||
#include <glibtop/proclist.h>
|
#include <glibtop/proclist.h>
|
||||||
|
#include <glibtop/procstate.h>
|
||||||
|
#include <glibtop/proctime.h>
|
||||||
|
#include <glibtop/procuid.h>
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@@ -17,14 +20,28 @@ static void print_pids(guint64 which, guint64 arg)
|
|||||||
|
|
||||||
pids = glibtop_get_proclist(&buf, which, arg);
|
pids = glibtop_get_proclist(&buf, which, arg);
|
||||||
|
|
||||||
printf("glibtop_get_proclist(%#llx, %llu) -> %lu processes\n",
|
for (i = 0; i < buf.number; ++i) {
|
||||||
which, arg, (unsigned long)buf.number);
|
glibtop_proc_time ptime;
|
||||||
|
glibtop_proc_uid puid;
|
||||||
|
glibtop_proc_state pstate;
|
||||||
|
|
||||||
for (i = 0; i < buf.number; ++i)
|
pid_t p = pids[i];
|
||||||
printf("%u ", pids[i]);
|
|
||||||
|
|
||||||
putchar('\n');
|
glibtop_get_proc_time(&ptime, p);
|
||||||
putchar('\n');
|
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);
|
g_free(pids);
|
||||||
}
|
}
|
||||||
@@ -34,7 +51,6 @@ int main()
|
|||||||
{
|
{
|
||||||
glibtop_init();
|
glibtop_init();
|
||||||
|
|
||||||
print_pids(GLIBTOP_KERN_PROC_ALL, 0);
|
|
||||||
print_pids(GLIBTOP_KERN_PROC_UID, getuid());
|
print_pids(GLIBTOP_KERN_PROC_UID, getuid());
|
||||||
|
|
||||||
glibtop_close();
|
glibtop_close();
|
||||||
|
Reference in New Issue
Block a user