0

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, &param);
    else if(strcmp(argv[3],"RR") == 0)
         sched_setscheduler((pid_t)pid, SCHED_RR, &param);
    else if(strcmp(argv[3],"OTH") == 0)
                 sched_setscheduler((pid_t)pid, SCHED_OTHER, &param);
    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

enter image description here

Further more, If I invoke shell.sh script manually on command prompt instead of boot.local, boostprio works properly !

Here is printscr

enter image description here

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 ?

Community
  • 1
  • 1
roll
  • 125
  • 13

1 Answers1

0

Looks like you have sincronization problems. (-:

On OpenSUSE 12.2 (and others) the service statup is assincronous and, because of this you cant rely on boot.local for this. In my opinion the best way to do this is write an init.d script who depends on sshd service (or $ALL services) and, on startup wait a little bit (just in case) and then, try to change sshd priority

Look at the script in /etc/init.d/skeleton as reference and write a new one with some changes in the header;

something like:

### BEGIN INIT INFO
# Provides:          sshprio
# Required-Start:    $ALL

or...

### BEGIN INIT INFO
# Provides:          sshprio
# Required-Start:    sshd
PerryWerneck
  • 124
  • 3
  • I dont think that it is concerned about asynchronous. Because the failure is sched_setscheduler. – roll May 10 '13 at 05:42
  • I tried initscript as /init.d/skeleton.It started sshd after boot. unfortunately it doesnt boost priority same as old. – roll May 10 '13 at 10:57