/* * KURT: KU Real Time Linux * $ProductId: KURT/linux/rt:rt.c 1.4 $ * * Copyright (C) 1997 by the University of Kansas Center for Research, * Inc. This software was developed by the Information and * Telecommunication Technology Center (ITTC) at the University of * Kansas. Partial funding for this project was provided by Sprint. This * software may be used and distributed according to the terms of the GNU * Public License, incorporated herein by reference. Neither ITTC nor * Sprint accept any liability whatsoever for this product. * * This project was developed under the direction of Dr. Douglas Niehaus. * * Authors: Balaji S. * * Please send bug-reports/suggestions/comments to realtime@ittc.ukans.edu * * Further details about this project can be obtained at * http://hegel.ittc.ukans.edu/projects/kurt/ */ #include #include #include #include #include #include #include #include #include #include #ifdef CONFIG_UTIME #include #endif #include #include #include #include void IntProc(int i) { struct rtparams param; int retval; retval = get_rtparams(0, ¶m); if (!retval) { printf("IntProc called for process with rt_id %d\n", param.rt_id); } /* Make this a normal process */ param.rt_id = 0; if (set_rtparams(0, SCHED_OTHER, ¶m)) { perror("set_rtparams: "); exit(1); } exit(0); } void do_stuff(void) { struct timeval time; static int i = 0; /* Just get the time and print it */ gettimeofday(&time, NULL); printf("(%d)Time is %d.%d.\n", i++, (int)time.tv_sec, (int)time.tv_usec); } int main(int argc, char **argv) { struct rtparams rt_param; signal(SIGINT, IntProc); if (argc != 2) { fprintf(stderr, "Usage : %s \n", argv[0]); exit(1); } /* set the scheduler for this process to be sched_kurt * and then set the rt_id of this procss properly */ rt_param.rt_id = atoi(argv[1]); rt_param.proc_req = 0; rt_param.period = 0; rt_param.priority = MAX_KURT_PRIORITY; if (set_rtparams(0, SCHED_KURT, &rt_param) < 0) { perror("set_rtparams:"); exit(1); } else { get_rtparams(0, &rt_param); printf("process rt_id = %d.\n", rt_param.rt_id); } while (1) { /* suspend the process till it is scheduled in * force it to suspend....If the parameter is 0 then rt_suspend * would not suspend if the kernel is not in real time mode */ if (rt_suspend(SUSPEND_IF_NRT | START_SCHED)) { perror("rt_suspend "); exit(0); } do_stuff(); } return 0; }