- Nice команда в линукс
- NAME
- SYNOPSIS
- DESCRIPTION
- RETURN VALUE
- ERRORS
- CONFORMING TO
- NOTES
- SEE ALSO
- COLOPHON
- Nice команда в линукс
- NAME
- SYNOPSIS
- DESCRIPTION
- AUTHOR
- REPORTING BUGS
- COPYRIGHT
- SEE ALSO
- Команда nice, или вежливые процессы
- How to use nice Command in Linux?
- Monitoring the nice value
- Using the standard top command
- Using the htop command
- Display the current niceness
- Standard usage of nice command in Linux
- Set a nice value for the bash
- Conclusion
Nice команда в линукс
NAME
nice - change process priority
SYNOPSIS
#include unistd.h> int nice(int inc); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): nice(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE
DESCRIPTION
RETURN VALUE
On success, the new nice value is returned (but see NOTES below). On error, -1 is returned, and errno is set appropriately.
ERRORS
CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001. However, the Linux and (g)libc (earlier than glibc 2.2.4) return value is nonstandard, see below. SVr4 documents an additional EINVAL error code.
NOTES
SUSv2 and POSIX.1-2001 specify that nice() should return the new nice value. However, the Linux syscall and the nice() library function provided in older versions of (g)libc (earlier than glibc 2.2.4) return 0 on success. The new nice value can be found using getpriority(2). Since glibc 2.2.4, nice() is implemented as a library function that calls getpriority(2) to obtain the new nice value to be returned to the caller. With this implementation, a successful call can legitimately return -1. To reliably detect an error, set errno to 0 before the call, and check its value when nice() returns -1.
SEE ALSO
nice(1), renice(1), fork(2), getpriority(2), setpriority(2), capabilities(7)
COLOPHON
© 2019 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.
Nice команда в линукс
NAME
nice - run a program with modified scheduling priority
SYNOPSIS
nice [OPTION] [COMMAND [ARG]. ]
DESCRIPTION
Run COMMAND with an adjusted niceness, which affects process scheduling. With no COMMAND, print the current niceness. Niceness values range from -20 (most favorable to the process) to 19 (least favorable to the process). Mandatory arguments to long options are mandatory for short options too. -n, --adjustment=N add integer N to the niceness (default 10) --help display this help and exit --version output version information and exit NOTE: your shell may have its own version of nice, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports.
AUTHOR
Written by David MacKenzie.
REPORTING BUGS
Report nice bugs to bug-coreutils@gnu.org GNU coreutils home page: http://www.gnu.org/software/coreutils/> General help using GNU software: http://www.gnu.org/gethelp/> Report nice translation bugs to http://translationproject.org/team/>
COPYRIGHT
Copyright © 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
nice(2), renice(1) The full documentation for nice is maintained as a Texinfo manual. If the info and nice programs are properly installed at your site, the command info coreutils 'nice invocation' should give you access to the complete manual.
© 2019 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.
Команда nice, или вежливые процессы
Когда на компьютере достаточно процессорного времени на исполнение всех процессов, нет необходимости в выставлении приоритетов. Но когда необходимо параллельно запустить несколько процессов, каждый из которых использует всё доступное процессорное время, может очень пригодиться утилита nice.
Команда nice запускает программу с изменённым приоритетом для планироващика задач. Слово «nice» в английском языке обозначает, в частности, «вежливый». По этимологии этой команды процесс с большим значением nice — более вежлив к другим процессам, позволяя им использовать больше процессорного времени, поскольку он сам имеет меньший приоритет (и, следовательно, большее «значение вежливости» — niceness value).
Наибольший приоритет (и наименьшее значение nice) — −20. 19, либо 20 — наименьший приоритет, но это, с другой стороны, самые вежливые процессы.
Чтобы посмотреть идентификатор и значение nice нужного процесса в системе, можно воспользоваться командой ps axl.
Пример использования команды nice — запуск ресурсоёмкой задачи в фоновом режиме, так, чтобы она выполнялась, но освобождала часть процессорного времени для других процессов, как только оно становятся им нужно. Таким образом можно, скажем, запустить кодирование OGG/MP3 с большим значением nice, чтобы оно происходило в фоновом режиме, используя не всё процессорное время, а то, что не используется другими процессами (с меньшим значением nice — то есть с большим приоритетом).
Чтобы запустить команду с определённым приоритетом, слева нужно добавить «nice -n значение_nice», либо «nice —adjustment значение_nice» (adjustment — настройка, регулировка).
То есть: nice -n значение_nice команда.
Если нужно изменить приоритет уже запущенного процесса, можно воспользоваться командой renice.
renice -n значение_nice id_процесса
Команда renice выводит старый и новый приоритет процесса.
Теперь, зная эти команды, можно управлять процессами так, чтобы определённые задачи выполнялись быстрее в случае, когда сразу много процессов используют всё доступное процессорное время.
How to use nice Command in Linux?
This article talks about the nice command in Linux. In Linux, each process has a nice value granted to it. This value influences the scheduling of processes and thereby determining the amount of CPU to spent on each one of them. “The more the nice value, the less the supposed priority”. This ultimately means that the more the process is nice, the more it allows other processes to get CPU.
The nice value ranges from -20 to 19 where -20 means a process is not nice, therefore must be given more priority, and 19 is the nicest process, therefore allows other processes to access resources before itself.
There is yet another priority in play, which denotes the actual priority in the eyes of the kernel. The Nice Value is not a real-time priority value but can be considered as a hint to the kernel about what range of priority a particular process should have.
Monitoring the nice value
We can not influence the value before monitoring it. Therefore, Linux has a set of system monitoring commands like top, atop, and htop that can be used to figure out nice values for every process in the system.
Using the standard top command
top is a simple command that provides information about the utilization of the system’s resources by each process. This includes knowledge related to CPU scheduling. By typing top in the terminal we get:
The two adjoining columns denote the priority-related values for every process. The PR column denotes the actual kernel-given priority of the process, whereas the NI column provides the Nice Value for each process. We have a complete article based on the top command if the user wants to gain further knowledge about it.
Using the htop command
htop is an interactive tool for displaying the usage of the system’s resources. It supports searching and filtering of values for the user’s convenience. We have to simply enter htop to obtain all the relevant information.
The fourth column denotes the nice value. This utility sorts the processes on a click on a specific column name. In the above figure, all the processes are sorted in decreasing order of nice value. Curious readers can visit here for more information about htop command.
Display the current niceness
The nice command without any parameters display the nice value of the bash running on the terminal.
As seen in the above figure, the default value is set to 0 . This implies that any command running using this terminal will have the same nice value.
Standard usage of nice command in Linux
The nice command can be used to start a process with a nice value specified by the user. This basically alters the actual priority assigned by the kernel.
Let us run an example for efficient understanding:
In the above snippet, we initiate the htop utility with a nice value of -10 . We can refer the result in the command’s output:
By default, htop runs with a nice value of 0 . It must be duly noted that to run a command with nice value less than 0, the root permissions are necessary.
Set a nice value for the bash
Instead of using nice command for every process we create, we can set a particular nice value to the current bash. It is done by:
The result can be noticed using the same htop command initiated above:
The htop command inherited the nice value of the bash which was used to run it.
Conclusion
Though the nice command has a simple usage and rather less technicality, but it stands out as a crucial command in the context of process scheduling. We have a bunch of articles on Linux commands which are worth a read. Make sure you check them out.