Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between nice and setpriority in unix

I'm trying to implement a different flavor of the 'nice' command of unix in C. I have seen the definitions of nice() system call and setpriority() call. The nice() call only increments/decrements the priority of the process. If I want to set the priority of a process to a particular value, can't I use the nice() call? Basically, other than how the priority is modified, is there any difference between nice() and setpriority() ?

like image 342
Aswin Parthasarathy Avatar asked Oct 01 '11 05:10

Aswin Parthasarathy


2 Answers

It's historical. nice() was introduced long before setpriority(). For backwards compatibility, the nice function was retained.

like image 192
Foo Bah Avatar answered Sep 21 '22 12:09

Foo Bah


nice sets your own priority (the niceness of the current process). setpriority lets you set the niceness of other processes (or process groups or users). Think of it as renice.

man 3p nice

int nice(int incr);

man 3p setpriority

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

like image 32
Chris Eberle Avatar answered Sep 23 '22 12:09

Chris Eberle