我如何从boot.local执行我的exe文件

时间:2013-05-09 11:02:17

标签: c boot init opensuse

我已经编写了一个代码来提高openSuSE 12.2系统上进程的优先级。

#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;
}

然后我写了一个bash脚本shell.sh调用boostprio二进制文件

#!/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

虽然新的sshd -p 911在启动时启动,但是boostprio exe不起作用并且不会提升sshd的优先级。它仍然是普通的优先事项。这是在putty上看到的图像文件

enter image description here

此外,如果我在命令提示符而不是boot.local上手动调用shell.sh脚本, boostprio正常工作!

这是printscr

enter image description here

因此,从/etc/init.d/boot.local调用时,我的/ usr / sbin / boostprio exe不起作用

此外,我在boostprio.c中打印了sched_setscheduler()函数,但在返回255时失败了 我认为这是实际问题。 但我不知道怎么弄清楚?

1 个答案:

答案 0 :(得分:0)

看起来你有sincronization问题。 ( - :

在OpenSUSE 12.2(和其他)上,服务statup是同步的,因此你不能依赖boot.local。在我看来,最好的方法是编写一个依赖于sshd服务(或$ ALL服务)的init.d脚本,并在启动时稍等一下(以防万一),然后尝试更改sshd优先级

查看/etc/init.d/skeleton中的脚本作为参考,并在标题中写一些新的更改;

类似的东西:

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

...或

### BEGIN INIT INFO
# Provides:          sshprio
# Required-Start:    sshd
相关问题