Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Operating Systems
Operating Systemsmedium

How does CPU scheduling work (preemptive vs cooperative)?

Tags
#scheduling#cpu#priorities
Back to categoryPractice quiz

Answer

Preemptive scheduling lets the OS interrupt tasks to ensure fairness and responsiveness. Cooperative scheduling relies on tasks yielding voluntarily, which can cause starvation if they don’t.

Advanced answer

Deep dive

Schedulers balance latency, fairness, and throughput:

  • Preemptive uses time slices and priority policies.
  • Cooperative is simpler but unsafe for untrusted tasks.
  • Real-time scheduling prioritizes deadlines over fairness.
  • Context switch cost affects time slice tuning.

Examples

Time-slicing:

Run task A for 5ms -> preempt -> run task B -> repeat

Common pitfalls

  • Assuming higher priority always improves throughput.
  • Using cooperative scheduling for mixed workloads.
  • Ignoring priority inversion.

Interview follow-ups

  • How do you prevent starvation?
  • What is priority inversion and how is it mitigated?
  • When would you use real-time scheduling?

Related questions

Spring
`@Scheduled`: fixedRate vs fixedDelay vs cron — what’s the difference?
#spring#scheduling#cron