Process:
When we execute a program, it is loaded into memor by OS & a process is created to show its running instance. Moreover OS allocates address space to each process with different address segments(stack, heap, code, data).
context switching:
Operating System executes a process at a time and but it continously switch between all running processes to execute them, this is called context switching. This context switching is so fast that although at a time only one process is executing but it will give a illusion that all are running in parallel.
Suppose you are doing coding in eclipse and also listening to songs in a VLC Player on same system. It will seems to us that oth “eclispe” and “music player” process are running in parallel but acually only one process is executing at a time by OS. To manage this OS assigns states to each process.
A Process has following states,
1.) New
When a process is in creation mode then its in new State. As soon as its created completely, OS will move it into Ready State.
When a process is in creation mode then its in new State. As soon as its created completely, OS will move it into Ready State.
2.) Ready
When a process is ready to be executed then OS puts it in a ready queue with other ready processes. When context switching happens, then OS need to pick another process to execute. Then OS picks the next process to run from this queue. Therefore, from this state process will move into Running State.
When a process is ready to be executed then OS puts it in a ready queue with other ready processes. When context switching happens, then OS need to pick another process to execute. Then OS picks the next process to run from this queue. Therefore, from this state process will move into Running State.
3.) Running
When a process is running i.e. OS is executing its instructions. From here 3 things can happen,
When a process is running i.e. OS is executing its instructions. From here 3 things can happen,
- If process gets blocked on any system API or I/O operation then OS moves this process to Blocked State
- If timeout happens then OS moves this process to Ready Queue and change is State to Ready.
- If Process ends then it moves to Done State
In first two scenarios Context Switching happens i.e. OS picks another process from ready queue to be in Running State
4.) Blocked
When a process is waiting for any event like I/O event or on signal event or stuck on any system call then its moved in to Blocked State. Once free from this wait then process will move to ready state.
When a process is waiting for any event like I/O event or on signal event or stuck on any system call then its moved in to Blocked State. Once free from this wait then process will move to ready state.
5.) Done
When a process is finished.
When a process is finished.