FANG Interview Question | Process vs Thread

preview_player
Показать описание

Checkout our bestselling System Design Interview books:

Other things we made:

Animation tools: Illustrator and After Effects

ABOUT US:
Covering topics and trends in large-scale system design, from the authors of the best-selling System Design Interview series.
Рекомендации по теме
Комментарии
Автор

This is how video lessons should be done; plenty of diagrams and animations instead of someone just talking.
Thanks!

fieryscorpion
Автор

Building a house is a process, but the people doing the work to install the pipes, paint the walls and do the electrical work are all the working threads within the process of building the house.

I like to use threads synonymously with “unit of work” or “thing that executes a specific piece of work / action for the process to complete successfully.

So if I run chrome, and have 10 tabs open, I will have 10 processes running. Within each process are 1 or many units of work (called threads) responsible for memory management, access, logic, etc.

I believe the house analogy works well in a lot of cases

Also, I was asked this question in an interview during a Comp. Sci. Fundamentals round during the systems design portion of my interview process at a large, global company we all interact with daily. (Keeping vague for obvious reason)

TannerBarcelos
Автор

Thread is the mechanism of sending instructions from a program(process) to CPU. Threads are OS based mechanisms, also processes are too but a process includes at least one thread. You can imagine that a process is encapsulation of a thread or threads. The OS looks at the program(when you click an executable), creates an executing process for the execution of the program and in the process the thread or threads are the carrier of instructions which are sent to the CPU. This is the execution mechanism of a program in an OS. When you create a thread rather than the main thread, you say to the OS that in this thread those instructions should run in a different context, that will create a context switch(that is execution of instruction(s) given by a thread to the CPU in a determined duration), and by that, you will see imaginary parallel execution of different instructions in different threads. Maybe one second long instruction set will be executed in a one short lived thread while another long running thread (especially main thread) keeps running and by that short living thread will not wait the long running thread to be finished. That is the magical part of multi threaded executions.

futurexjam
Автор

I have to admit... I have never seen such good explaination videos merged with animations and diagrams in my life. GREAT CONTENT SIR! Keep on doing what you do.

furiUfc
Автор

Fantastic video - concise and clear explanations accompanied by extremely helpful visuals. Couldn't ask for a better description within 4 minutes of time. Subscribed!

rickywj
Автор

This video perfectly summed up 100 lecture slides provided by my teacher without missing any key points... well done 👏👏

gabshu
Автор

Analogy for understanding process and thread
• In essence a program/process/thread is executing a job(a set of instructions). So, in that context, it’s no different than physical labour work where one executes a bunch of instructions from his/her brain and uses the required tools to complete a job
• Imagine you hire a fitter to mount your newly bought TV and you have already bought a TV mount. Here, the fitter represents a program. He has skills required to mount the TV(Set of instructions) and required tools(Data, library, plugins)
• Hiring a fitter is equivalent to installing a program. You have got commitment from him/her to work on your job. And he brings himself and loads the tools in your space ready to do the job. But, You have yet to extract the job from him. For this, you need to prepare some physical space near your TV and also give him the authorization to work at your home. This is the equivalent of creating a process where you allocate CPU and ram memory for the program to execute its job
• Just as a program can spin up multiple process, a fitter can bring multiple fitters to execute the same job. All of them work independently in their own physical space and with required authorization
• So, what's the analogy for threads? A fitter usually breaks the job into sub tasks. Here, mounting a TV can be broken in tasks like punching holes in the wall, preparing the Mount frame, adjusting the tilt etc. These subtasks represent individual threads. These threads are executed in the same memory/heap space just as the fitter performs his subtasks on his original physical space.
•Threads can be executed in parallel saving time. You can imagine this to be fitter performing tasks at the same time using his two hands. For example, one hand used to punch holes in the wall and other hand used to prepare the mount frame. This might sound like a stretch but there are some crazy people who could multitask with both hands

muzammilnxs
Автор

All information that I knew but would be hard-pressed to scoop out of my brain on demand - it's great to have clear and succinct refreshers like this to keep the neurons fresh

orterves
Автор

I keep getting confused between the two (threads and processes) but this depiction has helped me a ton. Thank you!

Nerdimo
Автор

Good refresher for me. Thanks once again for the awesome and meaningful video.

Vinod_Kumar
Автор

Recently came across your channel. Love the content. Very informative yet short enough to digest unlike most other tech videos

johnvandenberg
Автор

Also, would love to see videos on "heap" and "serialization / encoding" (some visuals on why in-memory representation is different from byte sequence would be super super helpful ). Thanks again for these great videos!!!!

jennwng
Автор

Great channel. Simple, short and straight-forward

milad
Автор

Thank you for this video! I got this question in an interview this week, and I wish I could have watched this video before the interview! So concise but detailed explanation! And now I get to know what is the purpose of "yield" in Python. None of the resources about it explain in context of OS and context switching...!

sungjuyea
Автор

clear concise explanation together with great graphics. Would love to know how you guys do your graphics.... Thank you...

syedahmad
Автор

Learnt more in 4 min than from 4 hrs of classes, thank you!

hugohultqvist
Автор

The standard here is exceptional. Thank you so much for this - I wish my lecturers had taken a leaf out of your book!

StephenBeale
Автор

Sir Alex, Please do in-depth videos. The content you post is so amazing but they are covered on a high level. Please go deep and explain things.

chetan_bommu
Автор

The graphics and animations are so good!
(And the content of course 😄)

Thanks for sharing!

martingallauner
Автор

I really love these videos!!! The visuals are very helpful to build mental models and understand these complex concepts - thank you so much!!!

jennwng