sched_setscheduler.c 639 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <sched.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include "test.h"

#define TEST(c) ((!c) ? 1 : (t_error(#c" failed: %s" ,strerror(errno)),0))

int main(int argc,char *argv[])
{
    struct sched_param param;
    int maxpri;

    maxpri = sched_get_priority_max(SCHED_FIFO);
    if(maxpri == -1) 
    {
        perror("get priority failed");
        return -1;
    }
    param.sched_priority = maxpri;
    TEST(sched_setscheduler(getpid(), SCHED_FIFO, &param));
    TEST(!(sched_getscheduler(getpid()) == SCHED_FIFO));
    
    return 0;
}