diff options
author | Benoît Dejean <bdejean@src.gnome.org> | 2007-06-25 17:27:27 +0000 |
---|---|---|
committer | Benoît Dejean <bdejean@src.gnome.org> | 2007-06-25 17:27:27 +0000 |
commit | 6b0bafcafb6a2bbaf9bacad6088bc801b8f070ae (patch) | |
tree | 2d0e827d230a206f2049cffd8043da68e499019d /examples | |
parent | c0856a39bd4d13714286aa968e0fe6b14e951a19 (diff) | |
download | libgtop-6b0bafcafb6a2bbaf9bacad6088bc801b8f070ae.tar.gz |
New API : glibtop_get_proc_affinity.
Implemented for linux.
svn path=/trunk/; revision=2609
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.am | 4 | ||||
-rw-r--r-- | examples/affinity.c | 34 |
2 files changed, 37 insertions, 1 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am index de6e6ef5..4567e383 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -8,7 +8,7 @@ DEFS = @DEFS@ noinst_PROGRAMS = first second pprint procargs df netlist \ mountlist procmap netload sysdeps timings \ - openfiles smp proclist mem wd + openfiles smp proclist mem wd affinity first_SOURCES = first.c first_LDADD = $(top_builddir)/lib/libgtop-2.0.la @@ -58,3 +58,5 @@ wd_LDADD = $(top_builddir)/lib/libgtop-2.0.la mem_SOURCE = mem.c mem_LDADD = $(top_builddir)/lib/libgtop-2.0.la +affinity_SOURCES = affinity.c +affinity_LDADD = $(top_builddir)/lib/libgtop-2.0.la diff --git a/examples/affinity.c b/examples/affinity.c new file mode 100644 index 00000000..cd670dae --- /dev/null +++ b/examples/affinity.c @@ -0,0 +1,34 @@ +#include <glibtop.h> +#include <glibtop/procaffinity.h> + +#include <glib.h> +#include <unistd.h> + +int main(int argc, char **argv) +{ + pid_t pid; + glibtop_proc_affinity buf; + guint16 *cpus; + size_t i; + + if (argc < 2 || !(pid = strtoul(argv[1], NULL, 0))) + pid = getpid(); + + glibtop_init(); + + cpus = glibtop_get_proc_affinity(&buf, pid); + + g_print("Process %u:\n" + " - all: %d\n", + (unsigned)pid, buf.all); + + for (i = 0; i != buf.number; ++i) + g_print(" - CPU#%u is set\n", cpus[i]); + + g_free(cpus); + + glibtop_close(); + + return 0; +} + |