What is a Process?
In this article we will discuss what is process and what are its states.
What is a Process?
Process is a an instance of a Program.
A Program is an executable file. Whenever we execute a program, then its loaded into memory by OS and a Process is created to represent this running instance. Every active Process has a unique ID associated with it that differentiate it from other process. Also, every process has its own address space and execution states.
For example, an executable file “eclipse” is a program. When we execute this program, a new process is created
Running a Program i.e.
Now check out the process,
To check out the running process we can use “ps” commands with following arguments “ef”
$ ps -ef | grep eclipse
varun 1949 1045 0 09:24 ? 00:00:00 /usr/lib/eclipse/eclipse
As we can see above that after running the program “eclipse” a process is created i.e. the instance of this program.
This has process has the ID “1949”.
Every process also has a parent ID i.e. the ID of the parent process that has created this new process. In above example parent process id is “1045”.
To check out all running process in you system you can use following command,
$ ps -elf
Address space of a process:
Each running process has a address space associated with it. Whenever a process starts, OS alloates a address space for it. This address space includes,
1.) Memory for Program Instructions loaded in from Program Image.
2.) Static Data
3.) Heap Area
Process States ans 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,
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 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 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
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 finished.
Join LinkedIn Group of Python Professional Developers who wish to expand their network and share ideas.
You can also follow us On Twitter : Follow @thisPtr