Process
Process : A program in execution
- A process includes
- text section (program code itself)
- stack/data/heap
- prgram counter (PC)
- CPU register contents
- PCB(Process Control Block)
-
An instance of a program that is loaded into memory and running (independent object)
- A unit of work in which system resources are allocated from the operating system.
- That is, as a dynamic concept, it means an executed program.
- Examples of allocated system resources
- CPU time
- Address space required to operate
- Independent memory area in the structure of Code, Data, Stack, and Heap
- Each process is allocated an independent memory area (structure of Code, Data, Stack, and Heap).
- By default, each process has at least one thread (the main thread).
- Each process runs in a separate address space, and one process cannot access the variables or data structures of another process.
- In order for one process to access the resources of another process, inter-process communication (IPC) must be used.
- Ex. Using communication methods using pipes, files, sockets, etc.
Thread
Thread : A unit of multiple flows running within a process.
- Threads are allocated a separate stack within each process, and the code, data, and heap areas are shared.
- A thread is a flow of execution that operates within one process, and is executed while sharing the address space or resources (heap space, etc.) within the process among the threads within the same process.
- Multiple threads in the same process share the same heap space. On the other hand, a process cannot directly access the memory of another process.
- Each thread has its own registers and stack, but the heap memory can be read from and written to each other.
- When one thread changes a process resource, other sibling threads can see the change immediately.