Cracking interview questions about OS processes (2/3)

Cracking interview questions about OS processes (2/3)

To crack interviews, we not only need to learn things but also need to learn them the right way. The key phrase here is "the right way". What IS the right way to learn? We'll see.

Let's say you need to learn about "Stack & Heap". How do we normally go about learning it?

Google to find a good article or a YouTube video, start reading/streaming and done.
Oh Yeah! I've learnt about "Stack & Heap" in 10 mins.
Did you, really?

Out Of Memory

Having aced the pre-interview coding test for Oswald Solutions, Pablo Passivo is in preparation for the interviews. Having learnt from his seniors that the company is known to ask Operating Systems related questions, he sat down a day before the interview to learn about "Commonly Asked OS Interview Questions". With the increased confidence of having covered OS fundamentals as well, he dozed off, dreaming about the CTC.

It's time for Pablo to enter the sacred room.

Round 1 - Coding Round ✅

Round 2 - OS Fundamentals

Interviewer: I'm creating a personal collection of errors. Can you help me with any OS related error that you know of?

(First thing that came to Pablo's mind was Segmentation fault. But, as he had "learnt" about the Out of Memory (OOM) error, T - 1 days before, he went with that)

Pablo: I know about the OOM error.

Interviewer: Nice! Can you tell me more?

Pablo: OOM is a state where the system has run out of memory and can no longer allocate memory to programs and the operating system. Hence, the system can no longer function properly or at least it cannot load any more programs. Modern systems do not run into this error as frequently as the older systems because modern processors can address large amounts of physical RAM and partially due to the advent of virtual memory.

Having given a good definition of OOM error that too in a single breath, Pablo be like

Nailed it, right? Nope. He just opened the Pandora's box!

The second question that interviewers love asking is to ask follow up questions.

  • Does OOM error occur during compile-time or run-time?
  • Tell me one scenario when your program will surely cause an OOM error.
  • My PC at home is having 1GB RAM. So, if I try to allocate close to 1GB of memory to a process, the system will throw an OOM error, right?
  • What happens to the process when it encounters an OOM error? Will the process always crash?
  • Is OOM error the same as Segmentation fault? How do they differ?
Le Pablo

Pablo, sadly, had to retreat :(

The placement results in the evening was even more shocking. Marese Experienze, who wasn't even among the preferiti, got selected. News is that, it was a clean sweep for her!

But, how in the world was she able to answer the follow-up questions?

Marese liked to learn things hands-on, experience them, and play around with it. Whatever little she learnt, she tried them out as well.

Some of you might have been curious when I mentioned earlier that asking a follow-up question was the second favorite question for Interviewers. What's their absolute favorite then?

If we see Pablo's response from earlier, it ends with "virtual memory". Though it might seem cool to use fancy words in our responses, you better know the jargon you're talking about. Interviewers will latch on to them (favorite, right there). They're known to be Feynman fans.

The Out Of Memory Byte bestows upon you the practical knowledge of the difference between the Out of Memory error & the Segmentation fault along with the know how to (or more importantly, not to) cause these. You'll experience these errors using programs and get to a state where you can answer all the follow up questions from earlier. Further, you'll be able to dig deeper on your own.

And if that's not enough, learn about Virtual Memory as well!

Excited to get started? Click below to enroll!

Fun with Process Internals

Marese's first assignment at work was to develop an in-house system monitor application. She started thinking about how the available Linux commands like top, netstat etc. might be fetching system & process info.

Does top ask the processor & RAM about who is giving them a hard time? Or does netstat stay in queue to get intel from the NIC card?

She was surprised to find out that these commands are just "pretty-printing" data from files under the /proc directory. Yeah, no expensive system calls!

Procfs or the /proc file-system

Being able to access system & process information with the ease of file reading, Marese completed all the project requirements with days to spare. Further research revealed to her that system/process state can be tweaked directly by writing to the files as well.

Take the Fun with Process Internals Byte to get a peek into the cool things we can do using the Proc File System (Procfs). You'll walk away with the practical knowledge of an all powerful Proc File System that controls the Linux world and will be able to:

  • Resurrect some accidentally deleted files
  • Monitor from behind the scenes what a process is doing
  • Write your own System Monitor utilizing Procfs
  • Explain better why random file access is slower than its sequential counterpart
  • Understand how you are able to run applications like your favorite video game that’s larger than the size of the RAM

Excited to get started? Click below to enroll!

The Challenge

We have an exciting challenge for you to take up, after completing the Fun with Process Internals Byte

On your Linux system, fetch the list of websites that your browser is communicating with.

Rules:
1. You're not allowed to use the ps / netstat commands

Submission:

How did you address this challenge with your practical knowledge? Blog about it on Medium and share the link on LinkedIn with #criodo #learnbydoing or in the comments section below.
Your blog may get recognised by us if you have dismantled the challenge successfully!

Recap

Bytes provide a framework for learning a key concept by doing. We have covered two Bytes here - Out Of Memory and Fun with Process Internals - that have enhanced your knowledge across Process Internals and OS Internals.

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. See Part 1 if you haven't already and we have Part 3 coming up with more Bytes.

Part 1 of the blog:

  1. Stack & Heap - Understand process Stack & Heap
  2. Process vs Thread - How does a thread differ from a process and when to use multi-threading?

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 have an even more exciting challenge in the upcoming blog, to test your Newfound Superpowers.
Stay tuned!
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.