Process is a program at the time of execution. A process is more than the program code. It includes the program counter, the process stack, and the contents of the process register, etc.
When a process executes, it changes the state, generally, the state of the process is determined by the current activity of the process.
Each process may be in one of the following states:
1. New: The process is being created.
2. Running: The process is been executing.
3. Waiting: The process is waiting for some event to occurs.
4. Ready: The process is waiting to be assigned to a processor.
5. Terminate: The process has finished execution.
The important thing is that only one process can be running in any processor at any time. But many processes may be in ready and waiting states. The ready process is loaded into a “Ready Queue“.
Explanation of Process States:
New -> Ready: The operating system creates a process and prepares the process to be executed, then the operating system moved the process into “Ready Queue“.
Ready -> Running: When it is time to select a process to run. The operating system selects one of the jobs from the ready queue and moves the process from the ready state to the running state.
Running -> Terminated: When the execution of a process has completed, then the OS terminates that process from running state.
Running -> Ready: When the time slot of the processor expired, then the operating system shifted the running process to the ready state.
Ready -> Running: When it is time to select a process to run. The OS selects one of the jobs from the ready queue and moves again the process from the ready state to the running state.
Running -> Waiting: A process is put into the waiting state. If the process needs an event to occur or an I/O device. The operating system doesn’t provide the I/O device then the process moved to the waiting state by the operating state.
Waiting -> Ready: The process in the blocked state is moved to the ready state when the event for which it has been waiting occurs.
We can Difference between Process and Thread given below:
Process vs Thread:
1. Process can't share the memory.
1. Threads can share memory and files.
2. In process, execution is very slow.
2. In thread, execution is very fast.
3. It takes more time to create a process.
3. It takes less time to create a process.
4. It takes more time to complete the execution and terminate.
4. It takes less time to complete the execution and terminate.
5. Process is loosely coupled.
5. Theads are tightly coupled.
6. Processes are not suitable for parallel activities.
6. Threads are suitable for parallel activities.
7. System calls are required to communicate each other.
7. System calls are not required.
8.Implementing the communication between processes is difficult.
8. Communication between two threads are very easy.