TASK_PID identifies an already running process whose current nice value is 5.
Change its absolute nice value to 12.
nice -n 5 sleep 60 &
TASK_PID=$!Which command is appropriate?
renice modifies an existing process. --priority sets the absolute value and --pid identifies the target process.
Detailed explanation
nice -n 12 "$TASK_PID"Incorrect. nice starts a command; it does not modify an existing PID.
Incorrect. nice starts a command; it does not modify an existing PID.
renice --priority 12 --pid "$TASK_PID"Correct. --priority 12 sets the absolute value for the process selected by --pid.
Correct. --priority 12 sets the absolute value for the process selected by --pid.
renice --relative 12 --pid "$TASK_PID"Incorrect. --relative 12 adds 12 to the current value, producing 17.
Incorrect. --relative 12 adds 12 to the current value, producing 17.
ps -o ni= -p "$TASK_PID"Incorrect. ps only displays the value.
Incorrect. ps only displays the value.
Try it yourself
An example you can run in a temporary verification environment.
nice -n 5 sleep 60 &
TASK_PID=$!
ps -o pid=,ni=,comm= -p "$TASK_PID"
renice --priority 12 --pid "$TASK_PID"
ps -o pid=,ni=,comm= -p "$TASK_PID"
kill "$TASK_PID"Expected result
変更前: NI欄が5
変更後: NI欄が12
※PIDとメッセージの書式は環境により異なるKey points
- Absolute versus relative priority changes
- Targeting a PID
- The difference between ps and renice
Notes
- Environment: Bash 5.2 / util-linux 2.39以降
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.