Cracking interview questions about OS processes (1/3)

Cracking interview questions about OS processes (1/3)

Being an intern/fresher, it is as important to have good OS/Database/Networks fundamentals as it is to have projects. But, it could be a pain to keep track of all the "theoretical" knowledge required to answer entry-level OS-based interview questions like these:

  1. You would've learnt about Stack & Heap of a process. How do they differ? Where does a local variable get stored? What about global/static ones?
  2. Ok, I can see on your resume that you've used multi-threading in a project. Can you help me understand how a process and a thread differ? Why did you use multi-threading?
  3. Nice! You have a project in C++. One day or other, you definitely would have come across Segmentation faults. What are they? Are they the same as an Out of Memory Error?

Now, all these questions have ready-made answers on the internet you can brush up a day or two before the D-day. The catch is that there's a perceivable difference between how one presents/talks about something they have experienced vs something they've read. Let me explain to you what that means.

We'll tackle some of these questions one-by-one.

Stack & Heap

Do a quick search for "Difference between Stack & Heap" and see what you can find (You'll be coming back, right? :)). Most probably you would've stumbled across something like this

https://www.slideshare.net/BaabtraMentoringPartner/functions-with-heap-and-stack-32841304

Ok, on to the main question - how do we "learn" these? Doesn't matter if we read this a 100 times or skillfully craft an acronym to remember these, they won't be of any use in a week or so. Even worse, what if the interviewer asks you how you know these for sure.

Oh no! Saying that you found it on a reputable blog (most certainly) won't get you the job.

OTOH, how about you found some way to experience the differences? What if you wrote code to see for yourselves if all of these are true?

In the Stack & Heap Byte, you will use programs to understand where the stack is used and where the heap comes into the picture. You'll see where they reside in the process' memory by utilizing Linux's Proc file-system. You'll also see where your variables get stored and more ..

Crio Byte: Stack & Heap

You'll walk away with practical knowledge of process Stack & Heap and will be able to:

  1. Show off with visualization, when and how the stack and heap get used in a process
  2. Look into memory addresses to figure out where they reside - stack, heap or any other segment of the process memory
  3. Prove to someone, that Stack & Heap grow in different directions, in a matter of minutes

Excited to get started? Click below to enroll!

Process vs Thread

Let's try a video lecture now

Some points discussed are:
1. Single-threaded process is represented by its address space
2. Threads share the same virtual address space
3. Each of the threads get to have registers & stacks of their own

Ok, good to know. But, how does this knowledge help us the next time we write a piece of code? What does it mean for us to know that threads share the same virtual address space? Should we be sad or happy?

We'll dig into the differences hands-on in the Process vs Threads Byte. You'll programmatically comprehend:

  • What it means to share/not share the virtual address space?
  • Do threads sharing resources have only merits? What happens to a multi-threaded process if one of its threads goes all Bear Grylls trying to access an "illegal" memory location?
  • Which part of your program will reap more performance improvement with multi-threading?
Crio Byte: Process vs Thread

With the Process vs Threads Byte in your skills arsenal, you'll be able to answer these questions without breaking a sweat:

  • Why creating a thread is light weight whereas creating a process is heavier?
  • Why should we handle memory access by threads more carefully than by processes?
  • Irrespective of whether a system is multi-core or not, which type of operations gain the most with threads, CPU intensive or I/O intensive?

Excited to get started? Click below to enroll!

Recap

We have covered two Bytes across two verticals that have overlaps - OS Internals (Stack & Heap) and Process Internals (Process vs Thread)

Did you go through the Bytes? If not, get on with it and experience the difference - crack those interview questions, once and for all.

That is not all. We have more Blogs coming up with more Bytes, spread out across these two verticals.

Part 2 of the blog:

  1. Out Of Memory - Why does a process run out of memory or hit a segmentation fault?
  2. Fun with Procfs - What is this mysterious virtual file-system named Proc File-system and what is its importance?

Part 3 of the blog:

  1. Virtual Memory - What is the difference between Virtual Memory and Physical Memory?
  2. Understanding Function Call Stack - What happens in memory when one function invokes another?

We will also have exciting challenges in the upcoming blogs, to test your Newfound Superpowers.
Stay tuned!

Want a sneak peek into the challenges?
Challenge 1 - Find out which websites your browser has opened; using a backdoor (without using "netstat/ps", of course)
Challenge 2 - Function a() calls b() which in turn calls c(). Can you hijack the call stack to return control from c() to a() directly instead of b()? (Poor b() :( )

Happy Learning By Doing!

You've successfully subscribed to Crio Blog
Great! Next, complete checkout to get full access to all premium content.
Welcome back! You've successfully signed in.
Unable to sign you in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Billing info update failed.