diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 20:34:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 20:34:44 +0000 |
commit | e3be059d4da38aa36f1aee1d56f8ceb943d92f1c (patch) | |
tree | 26edef31e4e503dd1c92a112de174f366dd61802 /testsuite/ps.test/test-schedbatch.c | |
parent | Initial commit. (diff) | |
download | procps-e3be059d4da38aa36f1aee1d56f8ceb943d92f1c.tar.xz procps-e3be059d4da38aa36f1aee1d56f8ceb943d92f1c.zip |
Adding upstream version 2:4.0.4.upstream/2%4.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testsuite/ps.test/test-schedbatch.c')
-rw-r--r-- | testsuite/ps.test/test-schedbatch.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/testsuite/ps.test/test-schedbatch.c b/testsuite/ps.test/test-schedbatch.c new file mode 100644 index 0000000..9b4d334 --- /dev/null +++ b/testsuite/ps.test/test-schedbatch.c @@ -0,0 +1,46 @@ +/* test-schedbatch.c - Create a process using SCHED_BATCH scheduler + * policy and nice value. + * Compile: gcc -o test-schedbatch -Wall test-schedbatch.c + * Usage: ./test-schedbatch [ <NICE> ] + * + * Author: Mike Fleetwood + * https://bugzilla.redhat.com/show_bug.cgi?id=741090 + */ + +#define _GNU_SOURCE +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#include <sched.h> +#include <sys/time.h> +#include <sys/resource.h> + +/* Defined in Linux headers only */ +#ifndef SCHED_BATCH +#define SCHED_BATCH 3 +#endif + +int main(int argc, const char *argv[]) +{ + int nice = 19; + struct sched_param sp; + char msg[50]; + + if (argc >= 2) { + nice = atoi(argv[1]); + } + sp.sched_priority = 0; +#ifdef SCHED_BATCH + if (sched_setscheduler(0, SCHED_BATCH, &sp)) { + perror("sched_setscheduler(0,SCHED_BATCH,{.sched_priority=0}"); + } +#endif /* SCHED_BATCH */ + if (setpriority(PRIO_PROCESS, 0, nice) || errno) { + (void)snprintf(msg, sizeof(msg), + "setpriority(PRIO_PROCESS, 0, %d)", nice); + perror(msg); + } + while (1) { + getchar(); + } +} |