From 5e21196a9c7ee8eee921d74f6b5eef2f1980ec97 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Thu, 26 Jan 2023 04:24:19 +0100 Subject: Basic qemu eviction test with signalled stepping and added rip syscall --- test/util.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'test/util.c') diff --git a/test/util.c b/test/util.c index 8b27578..11cba55 100644 --- a/test/util.c +++ b/test/util.c @@ -2,8 +2,10 @@ #include "test/util.h" -#include +#include #include +#include +#include #include #include #include @@ -69,6 +71,41 @@ read_stat_core(pid_t pid) return cpu; } +pid_t +pgrep(const char *bin) +{ + char path[PATH_MAX]; + char buf[PATH_MAX]; + struct dirent *ent; + char *cmp; + FILE *f; + DIR *dir; + pid_t pid; + + dir = opendir("/proc"); + if (!dir) err(1, "opendir"); + + pid = 0; + while (!pid && (ent = readdir(dir))) { + snprintf(path, sizeof(path), "/proc/%s/cmdline", ent->d_name); + f = fopen(path, "rb"); + if (!f) continue; + memset(buf, 0, sizeof(buf)); + fread(buf, 1, sizeof(buf), f); + if ((cmp = strrchr(buf, '/'))) + cmp += 1; + else + cmp = buf; + if (!strcmp(cmp, bin)) + pid = atoi(ent->d_name); + fclose(f); + } + + closedir(dir); + + return pid; +} + void print_counts(uint8_t *counts) { -- cgit v1.2.3-71-gd317