Cyclic Executive (ITI8510)

Allikas: Lambda
Real-Time Operating Systems and Systems Programming
[ @ ]

This lab is part of the end grading. Keep the program in directory "rtos/lab1" and name it cyclic.c for it to be found for checking-script.

Your task is to implement a small cyclic executive, which runs its tasks once in a second, otherwise idling. This will give tasks 3 priorities: normal (once a second), high (interrupts) and low (idling level).

The program should handle Ctrl+C interrupt for higher priority tasks. Implementation-wise you should use setitimer()(nice and difficult) or alarm()(simple) to deliver a signal every 300 milliseconds (or 1 second if you are using alarm()) to time the tasks. The SIGALRM should be handled with a handler which sets a global variable (use sig_atomic_t as type).

The "Idle" task should do nothing initially except for checking for arrived signal and running the tasks. You may want to add some method for doing low priority tasks, but remember to keep their segments short in order to catch the interrupt flag on time.

The tasks

There should be 5 tasks, write them as separate functions.

  1. Get the internal processor tick time with clock() (NOTE: clock() function on dijkstra is weird: don't panic if it does not work as you would imagine; it's not your fault)
  2. Get the internal time with time()
  3. check for file "test.txt" in the current directory, if it exists and you can open it, display its content, close it, delete it ( unlink() ).
  4. Display the time() value on screen (that you got in task #2)
  5. Get the processor tick time with clock() function and store the amount of time since task 1 to a global variable.
  • For SIGINT interrupt, write the file "test.txt" with the time stored in task #5. (Note that tasks 1 & 5 only exist to try to keep track of running time)
  • (Optional) For idle task, think of something interesting to do which can be interrupted upon SIGALRM arrival.

HINTS

  • For printing the clock() value, you can cast it to some type that you can show (for printf("%d\n", (int)clockvalue might work).
  • You can probably adapt some of the code from the interrupt practice assignment.

Deadline

I'd like the results by April, 13. Put the lab into your home directory under "rtos/lab1", name it "cyclic.c". Then send me an e-mail with your student number in it.