nice is a utility that allows you to adjust the scheduling priority of processes. It is used to run a command with a modified scheduling priority, which can help control CPU usage and improve system performance. The lower the nice value, the higher the CPU priority a process will have. By default, all processes run with a nice value of 0.
Basic Syntax
nice [options] [command]
Here, options specifies the scheduling priority of the command, which is executed after nice is called. If no options are specified, the command is run at the default priority level of 0.
Commonly Used Options
-
-n: This option sets the priority level of thecommand. A higher value fornmeans a lower scheduling priority, while a lower value means a higher scheduling priority. The default priority level is 0. -
-p: This option sets the priority of the process with the specified process ID (PID). This option is useful when you want to adjust the priority of a running process.
Useful Examples
-
nice -n 10 ./my_program: This runsmy_programwith a lower scheduling priority, so that other system processes can run more smoothly. -
nice -n -10 ./my_program: This runsmy_programwith a higher scheduling priority, giving it more CPU time and resources. -
nice -n 5 updatedb &: This runs theupdatedbcommand in the background with a lower scheduling priority. -
nice -p 1234 -n 10: This sets the scheduling priority of the process with PID 1234 to a value of 10. -
nice -p 1234 -n -10: This sets the scheduling priority of the process with PID 1234 to a value of -10.
Leave a Reply