I've written a code for boosting priority of a process on my openSuSE 12.2 system.
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
int printUsage(void)
{
printf("\nUsage:\nboostprio [pid] [priority: (0-99)] [policy: FF:RR:OTH]\n");
exit (1);
}
int main (int argc , char *argv[])
{
int pid = -1 ;
int pri;
struct sched_param param;
if(argc != 4 ){
printf("\nArgument miss match !!");
printUsage();
return -1;
}
if((strcmp(argv[1],"-h" ) == 0) || (strcmp(argv[1],"--help") == 0))
printUsage();
pid = atoi(argv[1]);
if(pid <= 0){
printf("\nPid is not correct!!\n");
return -1;
}
pri = atoi(argv[2]);
if((pri > 99) || (pri < 0)){
printf("\nPriority value is not valid !!\n");
return -1;
}
param.sched_priority = pri;
if(strcmp(argv[3],"FF") == 0)
sched_setscheduler((pid_t)pid, SCHED_FIFO, ¶m);
else if(strcmp(argv[3],"RR") == 0)
sched_setscheduler((pid_t)pid, SCHED_RR, ¶m);
else if(strcmp(argv[3],"OTH") == 0)
sched_setscheduler((pid_t)pid, SCHED_OTHER, ¶m);
else{
printf("\nInvalid scheduling policy type!!\n");
printUsage();
}
return 0;
}
and then i write a bash script shell.sh invoking boostprio binary file
#!/bin/sh
PID=`ps -ef | grep "sshd -p 911" |head -1 | awk '{print $2}'`
/sbin/boostprio $PID 95 RR
if [ "$?" == 0 ]; then
logger -t "Emergency shell is activated."
else
logger -t "Emergency shell is NOT activated !!"
fi
Although new sshd -p 911 is starting at boot, boostprio exe doesnt work and doesnt boost priority of sshd. It is still ordinary priority. Here is image file seen on putty
Further more, If I invoke shell.sh script manually on command prompt instead of boot.local, boostprio works properly !
Here is printscr
Consequently, my /usr/sbin/boostprio exe doesnt work when it is invoked from /etc/init.d/boot.local
Moreover I printed sched_setscheduler() func in boostprio.c and failed as returning 255 I think that is the actual problem. But i dont know how to figure out ?