-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnice.c
More file actions
41 lines (36 loc) · 925 Bytes
/
nice.c
File metadata and controls
41 lines (36 loc) · 925 Bytes
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
35
36
37
38
39
40
41
#define _GNU_SOURCE 1
#include "contain.h"
#include <sys/resource.h>
#include <sys/time.h>
#include <argp.h>
#include <stdbool.h>
#include <stdlib.h>
#include <err.h>
static struct argp_option nice_options[] = {
{"nice", 1020, "priority", 0, "Set process nice priority", 0},
{NULL, 0, 0, 0, NULL, 0 },
};
static int nice_value = 0;
static bool set_nice = false;
static error_t parse_nice_opt(int key, char *arg, struct argp_state *state)
{
(void)state;
switch(key) {
case 1020:
nice_value = atoi(arg);
set_nice = true;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp nice_argp = {
nice_options, parse_nice_opt, "", "Nice Priority", 0, 0, 0 };
int do_nice(void)
{
if (set_nice)
if (setpriority(PRIO_PROCESS, 0, nice_value))
err(1, "setpriority(PRIO_PROCESS, 0, %d)", nice_value);
return 0;
}