Beruflich Dokumente
Kultur Dokumente
The main code monitors two temperatures, which are always supposed to be equal. If they differ,
it indicates an alarm.
The main code stays in an infinite loop and ISR vReadTemperatures happens periodically due to
the hardware interrupts if one or both of the temperatures changes or a timer interrupts every few
ms to cause the execution to jump to ISR.
Suppose both temperatures have been 73o for a while and processor finished the execution of line
of code iTemp0 = iTemperatures[0]; ie iTemp0 = 73.
Suppose an interrupt occurs and that both temperatures changed to 74o. The ISR writes the value
into the elements of iTemperatures array.
Page 1
Page 2
Page 3
1. Contiguous Allocation
2. Non-contiguous Allocation
Contiguous Allocation:
Main memory usually into two partitions:
1. Resident OS, usually held in low memory with interrupt vector.
2. User processes held in high memory
OS maintains information about the allocated partitions and free partitions (hole).
Dynamic Storage-Allocation Problem; which concerns how to satisfy a request of size n from a
list of free holes.
Many solutions to this problem. The first-fit, best-fit and worst-fit strategies are the common,
used to select a free hole from the set of available holes.
1. First-t: Allocate the rst hole that is big enough
Page 4
2. Best-t: Allocate the smallest hole that is big enough; must search entire list, unless ordered
by size. Produces the smallest leftover hole.
3. Worst-t: Allocate the largest hole; must also search entire list. Produces the largest leftover
hole.
First-t and best-t better than worst-t in terms of speed and storage utilization
Neither first fit nor best fit is clearly better than the other in terms of storage utilization, but first
fit is generally faster.
Non-Contiguous Allocation:
Paging:
Memory-management scheme that permits the physical address space of a process to be
noncontiguous.
Process is allocated physical memory whenever it is available.
Paging avoids external fragmentation and the need for compaction.
Divide physical memory into xed-sized blocks called frames (size is power of 2, between 512
bytes and 8192 bytes).
Divide logical memory into blocks of same size called pages.
Keep track of all free frames.
To run a program of size n pages, need to nd n free frames and load program.
Set up a page table to translate logical to physical addresses.
Cause internal fragmentation.
Hardware support for paging:
Page 5
2. Describe the steps followed after an interrupt is caused by an I/O call. (Nov 2012)
Ans: Interrupt driven I/O cycle is shown below.
Page 6
A process is more than the program code, which is sometimes known as the text section.
It includes the current activity, as represented by the value of the program counter (PC) 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 memory that is dynamically allocated during process
run time.
Process is an active entity, but a program is passive entity, which is also referred as executable
file.
Operation on process:
The processes in most system can execute concurrently, and they may be created and deleted
dynamically. Therefore two mechanisms provided by OS for this are:
1. Process creation
2. Process termination
Process creation:
A process may create several new processes using create-process system call during the execution
of process. The creating process is called parent process and the new processes are called children
of that processes, forming a tree of processes.
Most OS including UNIX and Windows family identify the processes according to a unique
process identifier (pid), which is typically an integer number
Parent and children can share all resources. Children share subset of parents resources, but parent
and child share no resources.
When a process creates a new process, two possibilities exist in terms of execution:
Parent and children execute concurrently.
Parent waits until children terminate.
There are also two possibilities in terms of the address space of the new process:
Child duplicate of parent.
Child has a program loaded into it.
A UNIX example:
fork() is a system call and create a new process, which consists a copy of address space of the
original process. This allows the parent process to communicate with child process. Both process
Department of ECE, VKCET
Page 7
continue execution after system call fork(), but one difference: the return code for the fork() is
zero for child process, whereas the a nonzero pid of the child is returned to the parent.
exec() is a system call after fork(). Parent can create more children or it has nothing else to while
the child runs, it can issue a wait() system call to move itself in the ready queue until the
termination of child. The illustration is shown below:
Process Termination:
Process executes last statement and asks the OS to delete it by using the exit system call.
Output data from child to parent via wait system call.
Processs resources are deallocated by OS
Parent may terminate execution of children processes via abort system call for a variety of
reasons, such as:
Child has exceeded allocated resources.
Task assigned to child is no longer required.
Parent is exiting, and the operating system does not allow a child to continue if its parent
terminates.
A UNIX example to terminate a process is system call exit().
5. What is paging? How paging is implemented with TLB. (Oct. 2011)
Ans: Paging:
Non-Contiguous memory allocation scheme.
Memory-management scheme that permits the physical address space of a process to be
noncontiguous.
Process is allocated physical memory whenever it is available.
Paging avoids external fragmentation and the need for compaction.
Divide physical memory into xed-sized blocks called frames (size is power of 2, between 512
bytes and 8192 bytes).
Divide logical memory into blocks of same size called pages.
Keep track of all free frames.
To run a program of size n pages, need to nd n free frames and load program.
Set up a page table to translate logical to physical addresses.
Cause internal fragmentation.
Page 8
If the size of the logical address space is 2m, and a page size is 2n addressing units (bytes or
words) then the high-order m- n bits of a logical address designate the page number p, and the n
low-order bits designate the page offset d.
The logical address is as follows:
Where p is an index into the page table and d is the displacement within the page.
Implementation of Page Table
Hardware implementation of the page table can be done in several ways.
Department of ECE, VKCET
Page 9
A simple way is the page table is implemented as a set of dedicated registers. If the address
consists of 16 bits, and the page size is 8KB. The page table thus consists of eight entries that are
kept in fast registers. The use of registers for the page table is satisfactory if the page table
is reasonably small (for example, 256 entries). This is not suitable for large page table,
because fastest registers with large size in CPU is not feasible.
Another method is keeping page table in main memory. There is a Page-Table Base Register
(PTBR) points to the page table and a Page-Table Length Register (PRLR) indicates size of the
page table.
In this scheme every data/instruction access requires two memory accesses. One for the page
table and one for the data/instruction. Thus, memory access is slowed by a factor of 2.
The two memory access problem can be solved by the use of a special fast-lookup hardware
cache called associative memory or Translation Look-aside Buffers (TLBs).
The TLB is associative, high-speed memory. Each entry in the TLB consists of two parts: a key
(or tag) and a value. When the associative memory is presented with an item, the item is
compared with all keys simultaneously. If the item is found, the corresponding value field is
returned.
The search is fast; the hardware, however, is expensive. Typically, the number of entries in a TLB
is small, often numbering between 64 and 1,024.
A paging hardware with TLB is shown below.
Page 10
6. Consider the following set of processes with CPU burst given in milliseconds.
Process
Burst time
Priority
P1
10
3
P2
1
1
P3
2
3
P4
1
4
P5
5
2
a) Draw the Gantt chart that illustrates the execution of these process using the following
scheduling algorithms: FCFS, SJF and non-preemptive priority (a smaller priority number implies
a higher priority)
b) What is the turnaround time and waiting time of each process for the above algorithms?
(Oct. 2011)
Ans:
a) Gantt chart for FCFS
b) Turnaround time
FCFS:
P1 = 10ms, P2 = 11ms, P3 = 13ms, P4 = 14ms P5 = 19ms
SJF:
P1 = 19ms, P2 = 1ms, P3 = 4ms, P4 = 2ms, P5 = 9ms
Priority:
P1 = 16ms, P2 = 1ms, P3 = 18ms, P4 = 19ms, P5 = 6ms
Waiting time
FCFS:
P1 = 0ms, P2 = 10ms, P3 = 11ms, P4 = 13ms P5 = 14ms
SJF:
P1 = 9ms, P2 = 0ms, P3 = 2ms, P4 = 1ms,
P5 = 4ms
Priority:
P1 = 6ms, P2 = 0ms, P3 = 16ms, P4 = 18ms, P5 = 1ms
Page 11