Operating System Classnotes
Operating System Classnotes
Operating System Classnotes
A process is a program in execution. A process is more than the program code, which is
sometimes known as the text section. It also includes the current activity, as represented by the
value of the program counter and the contents of the processor’s registers. A process generally
also includes the process stack, which contains temporary data (such as function parameters,
return addresses, and local variables), and a data section, which contains global variables. A
process may also include a heap, which is a memory that is dynamically allocated during process
run time.
A program by itself is not a process. A program is a passive entity, such as a file containing a list
of instructions stored on disk (often called an executable file). In contrast, a process is an active
entity, with a program counter specifying the next instruction to execute and a set of associated
resources. A program becomes a process when an executable file is loaded into memory. So One
program can be several processes.
2. Define different types of process states. What are the different types of
queues? When processes reside in these queues, what are their states?
As a process executes, it changes state. The state of a process is defined in part by the current
activity of that process. A process may be in one of the following states:
• Waiting: The process is waiting for some event to occur (such as an I/O completion or
reception of a signal).
The objective of multiprogramming is to have some process running at all times, to maximize
CPU utilization. The objective of time sharing is to switch the CPU among processes so
frequently that users can interact with each program while it is running. To meet these
objectives, the process scheduler selects an available process (possibly from a set of several
available processes) for program execution on the CPU. For a single-processor system, there will
never be more than one running process. If there are more processes, the rest will have to wait
until the CPU is free and can be rescheduled.
1. Job queue – job queue consists of all processes in the system. As
processes enter the system, they are put into a job queue. Processes are
their new state in this queue.
2. Ready queue – The processes that are residing in main memory and are
ready and waiting to execute are kept on a list called the ready queue. This
queue is generally stored as a linked list. Processes are their ready state in
this queue.
3. Device queues – The list of processes waiting for a particular I/O device
is called a device queue. Each device has its own device queue. Processes
are their waiting state in this queue.
3. What are the benefits of thread over process? Explain with situations where
thread works better than process.
A thread is a basic unit of CPU utilization; it comprises a thread ID, a program counter, a register
set, and a stack. It shares its code section, data section, and other operating-system resources,
such as open files and signals with other threads belonging to the same process. Atraditional (or
heavyweight) process has a single thread of control. If a process has multiple threads of control,
it can perform more than one task at a time.
1. To switch from one process to another needs interaction with OS. But switching threads
don’t need OS interaction.
2. If one process is blocked, then another process can’t execute. But if one thread is
blocked or waiting for another thread in the same task can execute.
For example, during using a server, if a client is downloading a movie, which takes a lot of time
– using process, other clients can’t use the server for other purposes, they will have to wait. But
using threads both clients can use the server at the same time, even if the 1 client is stuck
st
downloading.
4. Creating a new process is about thirty times slower than creating a new thread. And
context switching is about five times slower.
4. What is critical section problem? Suppose there are two processes P3 and P4.
At some point P4 wishes to enter its critical section. Using Peterson’s solution,
write an algorithm to show that P4 can finally enter its critical section. Use 20 and
30 as turn values for P3 and P4 respectively.
Suppose a system consisting of n processes {P0, P1, ..., Pn−1}. Each process has a segment of
code, called a critical section, in which the process may be changing common variables, updating
a table, writing a file, and so on. The important feature of the system is that, when one process is
executing in its critical section, no other process is allowed to execute in its critical section. Two
processes can’t execute their critical sections at the same time. The critical-section problem is to
design a protocol that the processes can use to cooperate. Each process must request permission
to enter its critical section. The section of code implementing this request is the entry section.
The critical section may be followed by an exit section. The remaining code is the remainder
section.
Assume that the load and store machine-language instructions are atomic; that is, cannot be
interrupted. The two processes share two variables:
The variable turn indicates whose turn it is to enter the critical section.
The flag array is used to indicate if a process is ready to enter the critical section. flag[i] = true
implies that process Pi is ready!