1/* setidle.c: tell kernel to use SCHED_IDLE policy for an existing process
2   and its future descendents.  These background processes run only when some
3   cpu would otherwise be idle.  The process's priority is never dynamically
4   escalated to the point where its I/O actions may compete with that of
5   higher priority work */
6
7#include <sched.h>
8#include <errno.h>
9#include <stdio.h>
10
11#define SCHED_IDLE      6006
12
13int main(int argc, char *argv[])
14{
15       int pid;
16       struct sched_param param = { 0 };
17
18       if (argc != 2) {
19               printf("usage: %s pid\n", argv[0]);
20               return EINVAL;
21       }
22
23       pid = atoi(argv[1]);
24
25       if (sched_setscheduler(pid, SCHED_IDLE, &param) == -1) {
26               perror("error sched_setscheduler");
27               return -1;
28       }
29       return 0;
30}
31