-
Notifications
You must be signed in to change notification settings - Fork 1
/
really_renice.c
50 lines (40 loc) · 941 Bytes
/
really_renice.c
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
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <string.h>
#define usage "Usage: really_renice nicelevel pid..."
char buffer[512];
int main(int argc, char **argv){
setuid(0);
setgid(0);
stdout = stderr;
int status = 0;
if (argc < 3){
puts(usage);
return EINVAL;
}
char *Nice = argv[1];
long pid;
FILE *Seriously;
#define errcheck if (errno != 0){ status = errno; printf("Failed for PID %li:%s\n",pid,strerror(status)); continue; }
for (int i = 2; i < argc; i++){
errno = 0;
pid = atol(argv[i]);
errcheck
sprintf(buffer,"/proc/%li/autogroup",pid);
errcheck
Seriously = fopen(buffer,"w");
errcheck
fputs(Nice,Seriously);
errcheck
fclose(Seriously);
errcheck
setpriority(PRIO_PROCESS,(id_t)pid,atoi(Nice));
errcheck
}
return status;
}