File: affinity.c

package info (click to toggle)
libgtop2 2.40.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 8,072 kB
  • sloc: ansic: 25,393; sh: 7,089; makefile: 418; perl: 268; xml: 179; sed: 16
file content (34 lines) | stat: -rw-r--r-- 532 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
}