-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nicest: run a command with the highest nice/ionice/oom-adj
- Loading branch information
1 parent
6397db3
commit 9dfddc0
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/sh -eu | ||
# SPDX-License-Identifier: WTFPL | ||
|
||
usage () { | ||
cat <<- EOF | ||
usage: $0 COMMAND [ARGS...] | ||
$0 -p PID | ||
Run COMMAND ARGS... with lowest priority regarding CPU (nice(1)), | ||
I/O (ionice(1)) and OOM-adj (choom(1)). | ||
With -p, renice PID instead (and I/O nice and OOM-adj). | ||
EOF | ||
} | ||
|
||
if [ "${1-}" = -h ] || [ "${1-}" = --help ] | ||
then | ||
usage | ||
exit 0 | ||
elif [ $# -eq 0 ] | ||
then | ||
usage >&2 | ||
exit 64 | ||
fi | ||
|
||
has () { | ||
command -v "$1" > /dev/null 2> /dev/null | ||
} | ||
|
||
if [ $1 = -p ] | ||
then | ||
if [ $# -ne 2 ] | ||
then | ||
usage >&2 | ||
exit 64 | ||
fi | ||
has renice && renice -n 19 -p $2 | ||
has choom && choom -n 1000 -p $2 | ||
has ionice && ionice -c 3 -p $2 | ||
exit 0 | ||
fi | ||
|
||
has choom && set -- choom -n 1000 -- "$@" | ||
has ionice && set -- ionice -c 3 "$@" | ||
set -- nice -n 19 "$@" | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh -eu | ||
|
||
cd "$(dirname "$0")" | ||
|
||
die () { | ||
echo "$*" >&2 | ||
exit 1 | ||
} | ||
|
||
./nicest -p $$ > /dev/null | ||
|
||
./nicest true | ||
|
||
if ./nicest false | ||
then | ||
die "false should have exited with error" | ||
fi |