#include #include #include using namespace std; void NiceMe(int level); void ChangePrio(pid_t myPID, int level); void PrintPrio(pid_t pid); void ActiveDelay(void); void PrintLimits(void); int main() { PrintLimits(); pid_t myPID{getpid()}; PrintPrio(myPID); ActiveDelay(); ChangePrio(myPID, -1); ChangePrio(myPID, -19); ChangePrio(myPID, 10); PrintPrio(myPID); ActiveDelay(); NiceMe(-5); NiceMe(2); PrintPrio(myPID); ActiveDelay(); return 0; } void NiceMe(int level) { cout << endl; cout << "Calling nice(" << level << ") " << endl; if (-1 == nice(level)) { perror("\tError nice: "); } else { cout << "\tSuccess" << endl; } } void PrintLimits(void){ rlimit limits; if(-1 == getrlimit(RLIMIT_NICE, &limits)) { perror("\tError getrlimit: "); } else { cout << endl; cout << "For this process, the nice limit is:" << endl; cout << "\tHard: " << limits.rlim_max << endl; cout << "\tSoft: " << limits.rlim_cur << endl; } } void ChangePrio(pid_t myPID, int level){ cout << "Changing Priority to " << level << endl; if (setpriority(PRIO_PROCESS, myPID, level) == -1) { perror("\tError, Set Priority : "); } else { cout << "\tSuccess" << endl; } } void PrintPrio(pid_t pid) { int myPriority; cout << endl; errno = 0; myPriority = getpriority(PRIO_PROCESS, pid); if (errno != 0) { perror("\tError, Get Proiority: "); } else { cout << "For process " << pid << " my priority is " << myPriority << endl; } } void ActiveDelay() { for(int j = 0; j < 3'000; ++j) { for(int i =0; i < 1'000'000; i++) { int k = i * i - i + i; } } }