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
|
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/resource.h>
int main(int argc, char *argv[])
{
int niceness = 10;
if (argc >= 2) {
niceness = atoi(argv[1]);
}
errno = 0;
int rc = setpriority(PRIO_PROCESS, 0, niceness);
if (rc != 0) {
if (errno == EACCES) {
// With the PRIO_PROCESS invocation, EACCES is a lack
// of CAP_SYS_NICE which, if the syscall is allowed,
// could non-root with negative nice value or LSM
// denial.
printf("Insufficient privileges (EACCES)\n");
} else if (errno == EPERM) {
// With the PRIO_PROCESS invocation, EPERM is only
// possible with seccomp ERRNO(EPERM)
printf("Operation not permitted (EPERM)\n");
} else {
perror("Other setpriority error");
}
return 1;
}
printf("Successfully used setpriority(PRIO_PROCESS, 0, %d)\n", niceness);
return 0;
}
|