Example handle process priority in UNIX systems

This commit is contained in:
Fabio Scotto di Santolo
2025-07-05 16:02:58 +02:00
parent dd53e83af6
commit 204c34a462

19
chp6/nice.c Normal file
View 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;
}