2013-05-09 231 views
0

我已經編寫了一個代碼,用於在我的openSuSE 12.2系統上提高進程的優先級。我怎樣才能從boot.local執行我的exe文件

#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開始在啓動,sshd的的boostprio exe文件不工作和犯規提升優先級。這仍然是普通的優先事項。下面是圖像文件上膩子

enter image description here

看到更進一步,如果我在命令提示符,而不是boot.local在手動調用shell.sh腳本,boostprio正常工作!

這裏是printscr

enter image description here

因此,我的/ usr/sbin目錄/ boostprio EXE犯規當它從/etc/init.d/boot.local

而且調用工作我在boostprio.c中打印了sched_setscheduler()func,並返回255 我認爲這是實際的問題。 但我不知道如何弄清楚?

回答

0

看起來像你有sincronization問題。 ( - :

在OpenSUSE 12.2(和其他)上,服務statup是獨立的,因此你不能依賴boot.local來實現這個目的。在我看來,最好的方法是編寫一個init.d腳本誰在依賴於sshd服務(或$ ALL服務),並在啓動時稍微等一下(以防萬一),然後嘗試更改sshd優先級

看看/etc/init.d/skeleton中的腳本爲參考譜寫新的一個頭中具有一些變化;

類似:

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

或...

### BEGIN INIT INFO 
# Provides:   sshprio 
# Required-Start: sshd 
+0

我不認爲它關心異步。因爲失敗是sched_setscheduler。 – roll 2013-05-10 05:42:38

+0

我試過initscript作爲/init.d/skeleton.It啓動後啓動sshd。不幸的是,它不會像以往一樣提高優先級。 – roll 2013-05-10 10:57:35