A process is just a program in execution.
It’s a binary that is being executed. From Hemal Shah.
Process vs. Thread?
Processes are what actually execute the program. Each process is able to run concurrent subtasks called threads.
- Threads are sub-tasks of processes and if synchronized correctly can give the illusion that your application is performing everything at once. Without threads you would have to write one program per task, run them as processes and synchronize them through the operating system.
Each program has a main thread. If you don’t program multithreading into a program, when it launches as a process, it will always run on a single thread.
Processes vs. Threads
As explained by Hemal Shah…
- Processes can be on multiple threads
- A thread cannot own multiple processes. A thread is owned by a process
A process is just a program is being executed from a binary file (a sequence of 0s and 1s). All operating systems have their own binaries that they can execute (window is
.exe, Apple is
- At the lowest level, there is code and data. In Von Neumann architecture you have the saying that Code is data. Remember what you learned for MIPS, like an
addis the code, and the data is the two registers that you want to add together
- So at the lowest level, that is all there is to a binary being executed.
Now, how this relates to threads? Well, each software thread is just a process running from a binary.
But Hemal also talked about how a single process can run on multiple threads.
- So if you have two processes that run multithreading, it might actually slow both programs down
- The OS can take care of doing some optimization to finish the multithreaded job faster if possible
- this page is good https://www.geeksforgeeks.org/thread-in-operating-system/
So threads share CPU time. The technique is called Context Switching
Also, the main memory is just RAM.