GridVids
Sign in with YouTube

8 cores, 540 processes | Context Switching Interview Question

Mark watched
Don't Miss
Hide
Open in popup Open on YouTube

Vivek Gupta 19 days ago

This MacBook has 8 CPU cores and 540 processes running. How does each one get a turn? Through context switches, and "what is a context switch?" is a common OS interview question.

The answer to give: the OS saves one thread's registers and loads another's. It's cheaper between threads of the same process, because they share memory, so the core keeps the same page table.

From the video: • About 500 of the 540 processes were at 0% CPU, waiting for something like a click or a network packet • macOS runs a thread for up to 10 ms before it can switch to another • One switch costs about 1 to 2 µs, and none of your code runs during it • Past the number of cores, more busy threads can make a program slower

Sources: Apple's XNU source (osfmk/kern/sched_prim.c); Eli Bendersky, "Measuring context switching and memory overheads for Linux threads" (2018); OSTEP, chapter 26; nginx docs (worker_processes).

Subscribe for the next interview question.

#operatingsystem #interviewquestions #placements #shorts

Leave a like, comment, and subscribe for more.

Check out AlgoZenith: https://maang.in/

-----------------------------------------------

😃 ABOUT ME

I’m Vivek, an engineer, Ex-Googler, ICPC World Finalist turned educator, and founder of AlgoZenith. I’ve taught Data Structures, Algorithms, and Competitive Programming to over 3000+ students and worked with 10+ engineering colleges to bridge the gap between college learning and real-world tech careers. Through AlgoZenith, I help students crack top product-based companies and become industry-ready. On this channel, you’ll find videos on coding strategies, roadmaps, interview prep, problem-solving techniques, and everything you need to level up your software career. If that’s your thing, do subscribe and hit the bell icon so you don’t miss a thing 🙂

-----------------------------------------------

📲 SOCIALS

Instagram: https://www.instagram.com/vivekgupta.ai/ Twitter: https://x.com/vg19988 LinkedIn: https://www.linkedin.com/in/acraider/ Codechef (5 ⭐️): https://www.codechef.com/users/acraider Codeforces (Master, max. 2269): https://codeforces.com/profile/acraider

-----------------------------------------------

🏷️ TAGS

-----------------------------------------------

#️⃣ HASHTAGS

Education
#Vivek Gupta #learn to code #learn coding