Skip to content

Commit

Permalink
Make nice priority incremental even with setpriority(2)
Browse files Browse the repository at this point in the history
Provide a consistent `nice` command whether implemented by calling
setpriority(2) or nice(3).
  • Loading branch information
suominen committed Mar 13, 2024
1 parent 0545d51 commit a400eaa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Fixes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
30. Make nice priority incremental even with setpriority(2) to match
how it worked with nice(3) (Kimmo Suominen)
29. V6.24.10 - 2023-04-14
28. Restore skipping of the "$edit" and "Comments" tests when not running
on a terminal (Kimmo Suominen)
Expand Down
5 changes: 5 additions & 0 deletions sh.proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,11 @@ pfork(struct command *t, int wanttty)
if (t->t_dflg & F_NICE) {
int nval = SIGN_EXTEND_CHAR(t->t_nice);
#if defined(HAVE_SETPRIORITY) && defined(PRIO_PROCESS)
int oval;
errno = 0;
if ((oval = getpriority(PRIO_PROCESS, 0)) == -1 && errno)
stderror(ERR_SYSTEM, "getpriority", strerror(errno));
nval += oval;
if (setpriority(PRIO_PROCESS, 0, nval) == -1 && errno)
stderror(ERR_SYSTEM, "setpriority", strerror(errno));
#else /* !HAVE_SETPRIORITY || !PRIO_PROCESS */
Expand Down
6 changes: 6 additions & 0 deletions sh.sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,12 @@ execute(struct command *t, volatile int wanttty, int *pipein, int *pipeout,
if (t->t_dflg & F_NICE) {
int nval = SIGN_EXTEND_CHAR(t->t_nice);
# if defined(HAVE_SETPRIORITY) && defined(PRIO_PROCESS)
int oval;
errno = 0;
if ((oval = getpriority(PRIO_PROCESS, 0)) == -1 && errno)
stderror(ERR_SYSTEM, "getpriority",
strerror(errno));
nval += oval;
if (setpriority(PRIO_PROCESS, 0, nval) == -1 && errno)
stderror(ERR_SYSTEM, "setpriority",
strerror(errno));
Expand Down
7 changes: 7 additions & 0 deletions sh.time.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ donice(Char **v, struct command *c)
{
Char *cp;
int nval = 0;
#if defined(HAVE_SETPRIORITY) && defined(PRIO_PROCESS)
int oval;
#endif

USE(c);
v++, cp = *v++;
Expand All @@ -155,6 +158,10 @@ donice(Char **v, struct command *c)
else if (*v == 0 && any("+-", cp[0]))
nval = getn(cp);
#if defined(HAVE_SETPRIORITY) && defined(PRIO_PROCESS)
errno = 0;
if ((oval = getpriority(PRIO_PROCESS, 0)) == -1 && errno)
stderror(ERR_SYSTEM, "getpriority", strerror(errno));
nval += oval;
if (setpriority(PRIO_PROCESS, 0, nval) == -1 && errno)
stderror(ERR_SYSTEM, "setpriority", strerror(errno));
#else /* !HAVE_SETPRIORITY || !PRIO_PROCESS */
Expand Down
7 changes: 3 additions & 4 deletions tcsh.man.in
Original file line number Diff line number Diff line change
Expand Up @@ -6203,11 +6203,11 @@ see the
shell variable.
.
.It Ic nice Oo Cm + Ns Ar number Oc Op Ar command
Sets the scheduling priority for the shell to
Increments the scheduling priority for the shell by
.Ar number ,
or, without
.Ar number ,
to 4.
by 4.
With
.Ar command ,
runs
Expand All @@ -6218,8 +6218,7 @@ The greater the
.Ar number ,
the less cpu
the process gets.
The super-user may specify negative
priority by using
The super-user may decrement the priority by using
.Dl nice \- Ns Ar number Li \&...
.Pp
.Ar command
Expand Down

0 comments on commit a400eaa

Please sign in to comment.