From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: util-linux@vger.kernel.org
Subject: [bug] renice not POSIX compliant
Date: Sat, 14 Sep 2019 14:55:37 +0100 [thread overview]
Message-ID: <20190914135537.yps2umfx2nsynyii@chaz.gmail.com> (raw)
Hi, there are a few POSIX compliance issues with the "renice"
command from util-linux.
First and more importantly, per POSIX, like for "nice", "-n"
is meant to take an "increment"/"adjustment", not an absolute
value.
As in
renice -n 5 "$pid"
is meant to increase the nice value by 5. While the traditional,
BSD-style:
renice 5 "$pid"
sets its absolute value to 5.
util-linux added "-n" in 2009 for POSIX compliance (see
https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=7cfbafda9c484a8cadefc47ee115086e803d9391),
but the "-n" is just ignored. Since 2010, the --help message
does say that -n/--priority takes an "increment"
(https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=296351b0f112c821bffbe8ce7aa35d716251051d)
but that's not what happens in practice (it still sets the
niceness to the value specified).
$ nice -n 1 sh -c 'renice -n 2 "$$"; ps -o nice,comm -p "$$"; exit'
29606 (process ID) old priority 1, new priority 2
NI COMMAND
2 sh
Also, a POSIX renice utility is meant to parse the options the
usual (getopt(3)) way. In particular,
renice -gn 1 -- 123
Is meant to increase the niceness of pgid 123 by 1, but fails in
util-linux renice.
$ renice -gn 1 -- "$$"
renice: invalid priorty '-gn'
Try 'renice --help' for more information.
-p, -g, -u are meant to specify how *all* operands are to be
interpreted, they are not options that take arguments.
renice +1 123
renice +1 123 -u me
are unspecified by POSIX, so it's fine for util-linux to handle
the BSD way, but
renice -n 1 -u me -p 123
Is meant to increase the niceness of users "me", "-p" and "123".
Also, calling it "--priority" is quite misleading as the
niceness is rather the opposite of priority. GNU "nice" uses
"--adjustment" as the long-option equivalent of "-n" (note that
FreeBSD also calls it "priority" though)..
IMO, the best way to handle it would be to do a BSD-style
parsing when the first argument matches the [-+]?\d+ RE, and do
a POSIX getopt_long parsing otherwise with:
Change the (POSIX style) options to:
-n/--adjustment <num>: niceness increment
-v/--value (deprecated: --priority) <num>: exact niceness value
-g/--pgrp (no arg): interpret operands as gids.
-u/--user (no arg): interpret operands as user names/ids
-p/-pid (no arg): interpret operands as pids.
--help/--version...
And keep the
renice niceness [[-p/--pid] pid ...] [[-g/--pgrp] pgid ...] [[-u/--user] user ...]
usage for backward compatibility and BSD compatibility.
Note that there's currently a bug in the latest version of the
POSIX specification in that it says that positive increments
should *decrease* the niceness
(http://austingroupbugs.net/view.php?id=1286).
See
https://unix.stackexchange.com/questions/541673/how-do-i-start-a-shell-the-way-all-the-processes-ran-from-within-it-and-processe/541691#541691
for more details.
--
Stephane
next reply other threads:[~2019-09-14 14:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-14 13:55 Stephane Chazelas [this message]
2019-11-08 11:08 ` [bug] renice not POSIX compliant Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190914135537.yps2umfx2nsynyii@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).