Operating Systems - The Process Concept

What is a process?

A process is a program that is being executed by the CPU. So what is the difference between a program and a process? Well, when you write some code and compile it, the output is an executable file. This file is what we call a program, it's containing a set of instructions to perform a job on your computer. When you double click on the program, you start a process. You can start many processes, but it's being started from one program. For example, you can start the program notepad.exe multiple times and, and that results in multiple processes that behaves differently, depending on your actions (what you type in each notepad for example). Programs are stored in the secondary memory while processes are hang out in the primary memory. We say that programs are passive, and processes are active.

 

A process in primary memory

When a program is started, it is being read into the primary memory and starts to execute. The figure below describes how a process views itself in the primary memory.

 

                                                                          

                                                                    Figure: A process in primary memory

The number 0 in the figure indicates that the process have an address that starts at 0, and it goes to some arbitrary address (max in the figure), depending on how large the process is. All processes think that they begin on address 0. All they know about is themselves, they have no clue about other processes being executed. So all processes from their own perspective think that they starts working on the address 0. The operating system keeps track of where they actually are, it knows that the processes think that they are at the address 0, but in reality it may be somewhere in the middle of the primary memory.

The range from 0 to max is called address space. It consists of four main parts. The text-section, data-section, heap and stack. The text- and data-section have a fixed size, while heap and stack can increase in size.

1. Text-section. The text-section is the set of instructions that are being executed. The compiled code you write. I said that the text-section has a fixed size, this is natural since it's only instructions there. No instructions are added, nor are they deleted.

2. Data-section. The data-section consists of global variables and global constants. Data we know the size of from the very beginning, therefore it has a fixed size as well. Global variables are with the process under the whole lifetime, and its size doesn't change. The values it hold may change, but not the size of it.

3. Heap. The heap consists of dynamically allocated data. Like when the programmer uses the new and delete operators. By using new, you tell the computer that you want to use the heap to store something, or that you're done with something by using delete. It's very important that the programmer deletes data when it's purpose is fulfilled, otherwise the heap will just continue to grow and use massive amount of the primary memory.

4. Stack. The stack contains all temporary variables. For that reason, it does not have a fixed size. New variables may be declared, and old ones are removed. Unlike the heap, the stack manages itself. The programmer doesn't have to worry about deleting temporary variables from the stack.

 

In the operating system

The operating system must share resources fairly among all processes. Resources may be the processor itself, which process gets what part of the primary memory and how much, I/O devices etc. It also has to keep track of all processes. To keep track of all processes, the operating system uses a structure called Process Control Block (PCB).

 

Process Control Block

So what does the PCB contain? A lot of things:

1.Process state. Is the process running? Is it waiting for input/output? Is it executing? What is the process doing right now?

2. Program counter. What instruction is the process executing right now?

3. CPU-Registers. Processes have their own set of registers.

4. Scheduling information. What priority does the process have? Should it execute before another process?

5. Memory-information. Where in the primary memory is the process?

6. Accounting information. How much processor time have the process used since it started? Privileged time? User time?

7. I/O-information. What input/output devices is the process using? Network? Audio?

The PCB contain meta-data about the process.

 

Process states

Processes are in different states. There are five fundamental states. They may have different names in different operating systems, and there may be more states, but these are the five fundamental states that have to exist:

1. New. When a process is created, the operating system puts it in the state new. Here, the operating system will do some calculations to see if the process is allowed to run. Is there enough space in the primary memory? Are there other constraints?

2. Running. This is the state when the process is executing.

3. Ready. Processes are waiting for the processor to run it.

4. Waiting. Processes are waiting here too, but they are waiting for something else rather than the processor. Maybe it's waiting for the user to do something. Click a button.

5. Terminated. The process is about to exit. It have to wait for the operating system to terminate it.

 

Enjoyed this article? Give the teacher an apple.

cookie

1

Author

authors profile photo

Articles with similar tags

Comments