suppose the time it takes to switch between user and kernel modes is t1 and to switch between two processes is t2.Which is greater t1 or t2?
3 Answers
Theoretically it depends on the platform. In practice, a switch from one process to another typically goes from the original process to kernel mode, then the kernel decides which process to schedule next, then there's a switch from kernel mode to user mode running the second process.
As such, switching from one process to another includes a switch from user- to kernel-mode, plus more, so it'll be slower.
Comments
It depends on the platform. You should profile yours.
1 Comment
John Zwinck
You might try making a simple system call in a loop and seeing how fast that is. Then run a program which calls
sched_yield() a lot and see how that goes (how much time until it gets control back). I think you could learn something this way, with some refinements. That said, your answer about t2 being longer in general seems intuitively sensible.