Boosting Priority Of A Process
posted under
C program
,
C++ program
,
increasing priority
,
linux
,
priority
,
process
,
unix
by Anonymous
Sometimes it is necessary to increase the priority of a particular process in order to get better response or performance. This can be done using the command line using the "nice" command. To do the same thing and also control how a process its scheduled and its priority, the following program may be used. You need to have root access to perform these operations.
You can get the system values for the minimum and maximum priorities using the following functions:
int sched_get_priority_min( int ALGORITHM );
int sched_get_priority_max( int ALGORITHM );
ALGORITHM may be
- SCHED_RR (Round Robin)
- SCHED_FIFO(First In, First Out Queue Type Algorithm where the process is pre-empted only during an I/O operation)
- SCHED_OTHER(Default Linux Scheduling Algorithm)
- SCHED_BATCH(Batch scheduling)
#include <sched.h>
bool boostPriority( int pid, int priority )
{
bool boosted = true;
//Declare structure for storing scheduling information
sched_param p;
//Get the current scheduling information
//A value of 0 denotes the current process
//Otherwise, the process with the given pid is denoted
sched_getparam( pid, &p );
//This is the parameter we are interested in for changing the priority
//It is always best to get the current scheduling parameters, change
//the value of sched_priority and use the same sstructure to set
//the new priority
p.sched_priority = priority;
//Set the priority. Returns non-zero value if error occurs
if( sched_setparam( pid, &p) )
boosted = false;
return boosted;
}

Comment Form under post in blogger/blogspot