#include #include #include #include void* foo( void*p ) { int policy; struct sched_param param; if ( pthread_getschedparam( pthread_self(), &policy, ¶m ) == 0 ) printf( "policy: %d priority: %d\n", policy, param.sched_priority ); } int main() { pthread_t p; struct sched_param param; pthread_attr_t attr; memset( ¶m, 0, sizeof( param ) ); param.sched_priority = sched_get_priority_max( SCHED_FIFO ); #if 0 if ( sched_setscheduler( 0, SCHED_FIFO, ¶m ) == 0 ) printf( "succesfully selected FIFO scheduler\n" ); #endif printf( "max priority %d\n", param.sched_priority ); if ( pthread_attr_init( &attr ) ) printf( "problem attr init\n" ); if ( pthread_attr_setschedpolicy( &attr, SCHED_FIFO ) ) printf( "problem setschedpolicy\n" ); pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ); if ( pthread_attr_setschedparam( &attr, ¶m ) ) printf( "problem setschedparam\n" ); if ( pthread_create( &p, &attr, foo, 0 ) == 0 ) printf( "thread succesfully created\n" ); else printf( "problem creating thread\n" ); pthread_attr_destroy( &attr ); usleep( 1000000UL ); }