-1

There are two processes (P-A and P-B) running on the same CPU core. Process B is multithreaded. I want process A to be preempted after every 2 microseconds by a thread of Process B.

Is it possible to write a timer interrupt (or anything else) to preempt process A after a fixed interval of time (in microseconds)?

Scissor
  • 153
  • 2
  • 14
  • in a user-space program? – Daniel Alder Jan 19 '16 at 15:58
  • Yes, Daniel. I could have used alarm(), as suggested by @Chris, but I want to refrain from using signal mechanism as it itself takes at least 1-2 microseconds. Is it possible without signaling? – Scissor Jan 20 '16 at 08:47
  • Linux itself is not optimized for this use-case. But there are projects which implement such techniques (real-time aka RT) in the kernel. Without a modified kernel I don't believe you have something better than alarm. A short google search for "linux real-time" found the following: RTLinux, RTAI, LibeRTOS, Xenomai – Daniel Alder Jan 20 '16 at 09:07
  • @Scissor, you could do it in kernel space which now supports high-resolution timer. – Chris Tsui Jan 24 '16 at 03:30

1 Answers1

1

alarm system call is what you need. According to its manpage, alarm() arranges for a SIGALRM signal to be delivered to the calling process in seconds seconds. You can register your signal handler for SIGALRM by signal/sigaction interface.

Chris Tsui
  • 452
  • 3
  • 10