Use getpriority()/setpriority() instead of deprecated nice()
This is now similar to how renice(1) is implemented.
This commit is contained in:
parent
43057f3a39
commit
203b52c38a
16
nice.c
16
nice.c
|
@ -3,6 +3,8 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
@ -12,6 +14,7 @@ int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
long val = 10;
|
long val = 10;
|
||||||
|
int savederrno;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'n':
|
case 'n':
|
||||||
|
@ -26,15 +29,18 @@ main(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
nice((int)MAX(INT_MIN, MIN(val, INT_MAX)));
|
val += getpriority(PRIO_PROCESS, 0);
|
||||||
if (errno != 0)
|
if (errno != 0)
|
||||||
perror("can't adjust niceness");
|
weprintf("getpriority:");
|
||||||
|
val = MAX(PRIO_MIN, MIN(val, PRIO_MAX));
|
||||||
|
if (setpriority(PRIO_PROCESS, 0, val) != 0)
|
||||||
|
weprintf("setpriority:");
|
||||||
|
|
||||||
/* POSIX specifies the nice failure still invokes the command */
|
/* POSIX specifies the nice failure still invokes the command */
|
||||||
execvp(argv[0], argv);
|
execvp(argv[0], argv);
|
||||||
/* reached only on failure */
|
savederrno = errno;
|
||||||
perror(argv[0]);
|
weprintf("execvp %s:", argv[0]);
|
||||||
return (errno == ENOENT)? 127 : 126;
|
return (savederrno == ENOENT)? 127 : 126;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue
Block a user