Program, Process and Thread Explained in One Minute

Check out all my other posts in My Technical Articles

Yu-Ming, CHANG (he/him)
Dev Genius

--

This chart displays the hierarchy among Program, Process and Thread
This chart displays the hierarchy among Program, Process and Thread

This is an introductory post to the core terms of operating system: Program, Process and Thread. You will get a general sense of what they are and how they work together at a high level.

To put it another way, it’s not going to be a hard-core technical paper, but just an friendly introduction. If you’re looking for a more in-depth exploration, you could jump to the last section where I put all the references I used to write this post.

Program

Program is a static, or passive, entity stored in the disk. It is a file containing binary form of instructions.

A program could store high-level programming language directly if that language is compiled at run time. Such program is called interpreted program.

For example, we developers write code in high-level programming language such as C. Computer cannot read C directly so a compiler is in place to translate C into executable file, an exefile. This executable file is the Program.

This is a screenshot displays an original C file, and an executable file after it is compiled
This is a screenshot displays an original C file, and an executable file after it is compiled

On the other hand, JavaScript and Python are interpreted program so we don’t have to compile it first.

Process

Process is like an instance of a Program. When a program is loaded onto memory, it becomes Process and is now considered an active entity.

Process requires more resources comparing to Program because when it is running, it needs memory and CPU to do the fetching and calculation.

A program might associated with multiple process, and a process might includes multiple threads.

Thread

A thread is the basic unit of executable code in a process. It comes with its own set of registers and stack.

A single-thread process means that a process could only perform a task one at a time. There is also multi-threads process, meaning it could run multiple tasks at a time.

Of course multi-threads are more efficient, but it also brings some side effects that single thread wouldn’t encounter, such as deadlock and concurrency. (here is my article talking about concurrency in general programming)

JavaScript is single-threaded

In previous article about Event Loop in JavaScript, I mentioned that JavaScript is a single-threaded synchronous and blocking language. It uses event loop to implement asynchronous-like feature, but it is single threaded.

If you’re interested, Golang is a multi-threads language.

Reference

--

--

I enjoy the positive mind flow when writing code to solve a problem. This is my journey to become a software developer, though now working as a product owner