Example handle process priority in UNIX systems
This commit is contained in:
19
chp6/nice.c
Normal file
19
chp6/nice.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
ret = nice(0);
|
||||||
|
printf("Current nice by nice function: %d\n", ret);
|
||||||
|
ret = getpriority(PRIO_PROCESS, 0);
|
||||||
|
printf("Current nice by getpriority function: %d\n", ret);
|
||||||
|
if (setpriority(PRIO_PROCESS, 0, 10) == -1) {
|
||||||
|
perror("setpriority");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ret = getpriority(PRIO_PROCESS, 0);
|
||||||
|
printf("Current nice by getpriority function: %d\n", ret);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user