Util-Linux Archive on lore.kernel.org
 help / color / Atom feed
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
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

As in

renice -n 5 "$pid"

is meant to increase the nice value by 5. While the traditional,

renice 5 "$pid"

sets its absolute value to 5.

util-linux added "-n" in 2009 for POSIX compliance (see
but the "-n" is just ignored. Since 2010, the --help message
does say that -n/--priority takes an "increment"
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
  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.

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

for more details.


             reply index

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 ` Karel Zak

Reply instructions:

You may reply publically 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:

* 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 \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Util-Linux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/util-linux/0 util-linux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 util-linux util-linux/ https://lore.kernel.org/util-linux \
	public-inbox-index util-linux

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git