Difference between nice and setpriority in unix

I'm trying to implement a different flavor of the nice command on Unix in C. I have seen the definitions of calling nice () and calling setpriority (). The nice () attribute only increases / decreases the priority of the process. If I want to set the priority of a process to a specific value, can I use the nice () call? Basically, besides changing the priority, is there a difference between nice () and setpriority ()?

+7
source share
3 answers

This is historical. nice() was introduced long before setpriority() . For backward compatibility, the nice function has been retained.

+8
source

nice sets its own priority (subtlety of the current process). setpriority allows you to set the appeal of other processes (or groups of processes or users). Think of it as renice .

man 3p nice

int nice (int incr);

3p man setpriority

int setpriority (int, id_t who, int value);

+8
source

nice() changes the good value of the current process compared to its current good value, so the process does not need to know about its start with a good value, it only cares that it is better in the system (for example: the process starts a child who does some background processing, the child puts himself well).

setpriority() case is used when the user explicitly sets absolute pleasant values ​​for specific processes.

+2
source

All Articles