M.Sc. Computer Science
Computer Systems
Additional Questions on Week 6 Materials – Part I
Question #1: What is a program? and what is a process? Discuss as many differences between them as
you can imagine.
Program: A program is a group of instructions to carry out a specified task. When we execute a
program that was just compiled, the OS creates a process to execute the program. Execution of the
program starts via GUI mouse clicks, command line entry of its name, etc. A program is a passive
entity as it resides in the secondary memory, such as the contents of a file stored on disk. One program
can have several processes.
Process: A process is a program in execution. The term process refers to program code that has been
loaded into a computer’s memory so that it can be executed by the CPU. A process can be described as
an instance of a program running on a computer or as an entity that can be assigned to and executed on
a processor. A program becomes a process when loaded into memory and thus is an active entity.
Difference between Program and Process:
Program Process
1. Program contains a set of instructions
designed to complete a specific task.
Process is an instance of a program.
2. Program is a passive entity as it resides in
the secondary memory.
Process is a active entity as it is created during
execution and loaded into the main memory.
3. Program exists at a single place (such as a
disk) and continues to exist until it is
deleted.
Process exists for a limited span of time as it
gets terminated after the completion of task.
4. Program does not have any resource
requirement, it only requires memory
space for storing the instructions.
Process has a high resource requirement, it
needs resources like CPU, memory address, I/O
during its lifetime.
5. Program does not have any control block
or context.
Process has its own control block called PCB as
well as its context.
Question #2: What is a Process Control Block and describe its role in a multi-programming / multi-
processing OS environment?
Process control block (PCB) is a data structure which is associated with any process and provides all
the complete information about that process. The process control block is “the manifestation of a
process in an operating system”. Process control block is important in multi-programming environment
as it captures the information pertaining to the number of processes running simultaneously.
At any instance, a process will be having various information associated with it like Process ID, state,
priority, program counters, memory pointers, accounting information etc. All such information is stored
in the PCB. It is an important tool that helps the OS support multiple processes and provide for
multiprocessing. It contains sufficient information such that if an interrupt occurs, the process can
begin from the point where it left later as if nothing had happened. Furthermore, it can be said that the
set of the process control blocks give the information of the current state of the operating system.
Question #3: List down three reasons for a process to move from running state to blocked state?
A process is put into the blocked state if it requests something for which it must wait. A request to the
OS is usually in the form of a system call. A process may enter blocked state when:
(a) it issues a request for IO (read / write) to a file on secondary storage (disk / usb etc) or a
network socket / connection.
(b) it requests for a resource (such as a memory, a semaphore, a mutex etc) which is currently not
available and being used by another process
(c) it tries to access a protected section of code that is currently locked by some other process /
thread.
Question #4: Multi-programming (or multi-tasking) enables more than a single process to apparently
execute simultaneously. How is this achieved on a uniprocoessor where we have only one CPU?
Multi-programming is achieved on a uniprocessor by the concept of scheduling. Every process can be
given a certain amount of time, called a timeslice and when the timeslice of a process is finished, the
CPU scheduler switches to a different process. The ultimate goal is to keep the system responsive while
really maximising the processor’s ability to process.
Question #5: In Linux/Unix, whether all processes are created by using fork() system call? Explain.
No, the first process is created by the operating system (there is no other process to fork it from). The
rest of the processes are created using fork().
Question #6: Calculate number of times hello is printed:
int main() {
fork();
fork();
fork();
printf(“hello\n”);
return 0;
}
The number of times ‘hello’ is printed is equal to number of processes created. Total Number of
Processes = 2^n, where n is number of fork system calls. So here n = 3, 2^3 = 8
Question #7: Predict the Output of the following program:
int main() {
int x = 1;
if (fork() == 0)
printf(“Child has x = %d\n”, ++x);
else
printf(“Parent has x = %d\n”, –x);
return 0;
}
Output:
Parent has x = 0
Child has x = 2
(or)
Child has x = 2
Parent has x = 0
Here, global variable change in one process does not affected two other processes because data/state of
two processes are different. And also parent and child run simultaneously so two outputs are possible.
Question #8: In Linux, a process can be in a zombie state. What does this mean?
The process has finished its execution, but the parent has not invoked a wait() system call for it yet. As
a result, process control block of the dead process can still be found in the operating system kernel
(process queues).