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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <sched.h>
int main() {
struct sched_param params;
int done = 0;
struct timeval tv;
time_t startsec;
unsigned long int loops;
int outer_loops;
params.sched_priority = 1;
pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶ms);
{
struct sched_param par;
par.sched_priority = sched_get_priority_min(SCHED_FIFO);
if(sched_setscheduler(0,SCHED_FIFO,&par)==-1){
fprintf(stderr,"das_watchdog: Unable to set SCHED_FIFO realtime priority for the watchdog thread. Exiting.\n");
return 0;
}
}
gettimeofday(&tv,0);
startsec = tv.tv_sec;
printf("My pid is %d\n",getpid());
sleep(1);
#if 0
while(!done) {
gettimeofday(&tv, 0);
if(tv.tv_sec - startsec > 10)
done = 1;
}
#else
for (outer_loops = 0; outer_loops < 10; ++outer_loops) {
for (loops = 0; loops < 1000000000; loops++)
{
done += 1;
//sched_yield();
}
}
#endif
exit (EXIT_SUCCESS);
}
|