A line or circulate of execution in utility software program is all the time carried out by a thread. A thread is a single, unbiased circulate or line of execution. All utility software program first begins a course of, after which the method begins at the least one thread, known as the first thread, to do one thing. If essential, a course of may also begin a number of threads. All these threads share the assets which can be assigned to the method by the working system.
Course of and Program
A course of is a working program – no confusion right here. When the working system runs a program, it’s known as a course of. So a program can run a number of instances on the identical time, creating a number of processes. Additionally a program can create a number of processes inside itself. Every course of has a novel ID assigned by the OS known as the method ID.

- A course of has at the least one thread, known as the first thread.
- When a course of begins, reminiscence and assets are allotted to it, and it could actually comprise a number of threads.
- A course of may also have a number of different threads, all of which share assets and time-share their execution.
- A program is one thing written by a programmer, and a working program begins as a course of, so the run-time entities of a program are the method and its threads.
- Threads exist as a subset of a course of, however processes are unbiased.
- A course of with a number of threads has management over which threads run and when, with respect to beginning, ready, and stopping threads.
Course of Sort
Primarily, there are two kinds of event-specific processes: I/O-bound processes and CPU-bound processes.
- I/O certain processes: If a program/course of spends extra time on I/O than on computation, then it’s known as an I/O certain course of.
- CPU-bound processes: If a program/course of spends a variety of time on CPU operations (computing) and doesn’t generate many I/O requests, then it’s known as a CPU-bound course of.


Every course of consists of a number of sections.
Article: That is the place the code for the method resides. It is a read-only part.
knowledge: That is the place international and statically initialized variables are saved.
Rodata: That is the place fixed variables are saved.
bss (block beginning with image): That is the place international and static uninitialized variables are saved.
stack: That is the place native variables and performance calls are saved.
heap: That is the place consumer allotted reminiscence is saved when the consumer makes use of malloc, calloc, new and so on.


For extra info, see right here. Great post on memory layout Muhammad Hassan Shah
What are threads?
A thread is a unit of execution inside a course of. A course of can comprise a number of threads. It comes with its personal set of registers and stack. A single-threaded course of implies that the method can solely execute one job at a time. There are additionally multi-threaded processes, which implies that it could actually execute a number of duties at a time. In fact, multi-threading is extra environment friendly, but it surely additionally introduces unwanted effects that single threading doesn’t have, resembling deadlocks and concurrency.
You will need to perceive that some languages help multi-threading and a few don’t, for instance C++ helps multi-threading however JavaScript is a single-threaded language and doesn’t help multi-threading.
abstract
In abstract, a course of is an occasion of a program with its personal deal with house, stack and heap. A course of could have a number of threads, but it surely has at the least one thread. All threads of a course of have separate stacks, however share a heap. If a course of has just one thread, it could actually solely use one core. Most fashionable CPUs have between 8 and 64 cores. So, with multithreading, every thread can run on a number of cores, leveraging extra assets and making your program extra environment friendly.
I hope this helps. Thanks.
You may also like: Touring Salesman Downside, Movement Blocks in Scratch Programming, Microbit Programming for Youngsters

