2011-09-25 14:45:43 +05:30
|
|
|
/* 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>
|
|
|
|
|
2012-06-11 17:41:23 +05:30
|
|
|
/* Defined in Linux headers only */
|
|
|
|
#ifndef SCHED_BATCH
|
|
|
|
#define SCHED_BATCH 3
|
|
|
|
#endif
|
|
|
|
|
2011-09-25 14:45:43 +05:30
|
|
|
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;
|
2012-10-30 16:06:04 +05:30
|
|
|
#ifdef SCHED_BATCH
|
2011-09-25 14:45:43 +05:30
|
|
|
if (sched_setscheduler(0, SCHED_BATCH, &sp)) {
|
|
|
|
perror("sched_setscheduler(0,SCHED_BATCH,{.sched_priority=0}");
|
|
|
|
}
|
2012-10-30 16:06:04 +05:30
|
|
|
#endif /* SCHED_BATCH */
|
2011-09-25 14:45:43 +05:30
|
|
|
if (setpriority(PRIO_PROCESS, 0, nice) || errno) {
|
|
|
|
(void)snprintf(msg, sizeof(msg),
|
|
|
|
"setpriority(PRIO_PROCESS, 0, %d)", nice);
|
|
|
|
perror(msg);
|
|
|
|
}
|
|
|
|
while (1) {
|
|
|
|
getchar();
|
|
|
|
}
|
|
|
|
}
|