Skip to content
Advertisement

Changing process priorities

Building off of this, I would like to change process priorities based on RAM usage. I’m perfectly aware that this isn’t always the best way to change priorities, but this is just for a project. I’m trying to use renice and execvp to set process priorities.

The problem is that I want to launch renice with additional parameters to change the process priority while the program is running. The problem is that when I run execvp with the correct #include it bounces an error with a lot of dependencies.

My main.c has two arrays. One has the process IDs and the other has their corresponding RAM usage and they get sorted in descending order. Is there any way to change process priorities with this information?

main.c

JavaScript

Makefile

JavaScript

Advertisement

Answer

I did more digging and found some functions that are helpful.

Include these:

JavaScript

Then, if you wanna see some info with only the process ID:

JavaScript

Or if you just wanna set priorities(set_user_nice actually changes priorities in real time, not just the nice value):

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement