日期:2014-05-16 浏览次数:20868 次
#include <stdio.h>
#include <pthread.h>
#include <sched.h>
main()
{
    struct sched_param param;
    int policy;
    if (pthread_getschedparam(pthread_self(), &policy, ¶m) != 0)
        perror("pthread_getschedparam:");
    printf("sched_priority:%d\n", param.sched_priority);
    if (pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m) != 0)
        perror("pthread_setschedparam:");
    if (pthread_getschedparam(pthread_self(), &policy, ¶m) != 0)
        perror("pthread_getschedparam:");
    if (policy == SCHED_RR)
        printf("policy is SCHED_RR\n");
    else if (policy == SCHED_OTHER)
        printf("policy is SCHED_OTHER\n");
    else if (policy == SCHED_FIFO)
        printf("policy is SCHED_FIFO\n");
    else
        printf("policy is %d\n", policy);
    while (1)
    {
        printf("In while (1)\n");
        sleep(5);
    }
    return 0;
}