Sei sulla pagina 1di 11

Ignou Study Helper

www.ignousite.blogspot.com

MASTER OF COMPUTER
APPLICATIONS
(MCA)
MCA/ASSIGN/SEMESTER-IV

ASSIGNMENTS
(July - 2016 & January - 2017)

SCHOOL OF COMPUTER AND INFORMATION SCIENCES


INDIRA GANDHI NATIONAL OPEN UNIVERSITY
MAIDAN GARHI, NEW DELHI – 110 068

Ignou Study Helper


www.ignousite.blogspot.com
Ignou Study Helper
www.ignousite.blogspot.com
Q1. Consider the following set of processes with arrival times and CPU execution times
given in milliseconds. A process with a larger priority number has a higher priority. If any
assumptions made by you, state them.

Arrival Execution
Process Priority
Time Time
P1 0 4 5
P2 3 12 4
P3 5 9 3
P4 5 2 2
P5 7 6 1

(i) Draw the Gantt charts illustrating the execution of these processes using the FCFS,
SJF, Round Robin (with quantum = 1) and Priority Based Scheduling algorithms.
(ii) Also calculate the average turnaround time, average waiting time, processor utilization
and throughput for each of the algorithms mentioned in (i).
Answer:

First-Come First-Serve (FCFS)


The simplest scheduling algorithm is First Come First Serve (FCFS). Jobs are
scheduled in the order they are received. FCFS is non-preemptive. Implementation is
easily accomplished by implementing a queue of the processes to be scheduled or by
storing the time the process was received and selecting the process with the earliest
time.
FCFS tends to favour CPU-Bound processes. Consider a system with a CPU-bound
process and a number of I/O-bound processes. The I/O bound processes will tend to
execute briefly, then block for I/O. A CPU bound process in the ready should not have
to wait long before being made runable. The system will frequently find itself with all
the I/O-Bound processes blocked and CPU-bound process running. As the I/O operations
complete, the ready Queue fill up with the I/O bound processes.

If the processes arrive as per the arrival time in the given table of question, the Gantt chart will be
as follows:

P1 P2 P3 P4 P5
0 4 16 25 27 33

Time Turn around time= Waiting Time =


Process Process Process Completed-Process Turn around time-
Completed Submitted Processing time
0 - - -
4 P1 4-0 = 4 4-4 = 0
16 P2 16-3 = 13 13-12 = 1
25 P3 25-5 = 20 20-9 = 11
27 P4 27-5 = 22 22-2 = 20
33 P5 33-7 = 26 26-6 = 20
Ignou Study Helper
Average turn around www.ignousite.blogspot.com
time = (4+13+20+22+26)/5 = 17

Average Waiting time =(0+1+11+20+20)/5 = 52/5 = 10.4

Process Utilization =(33/33)*100 =100%

Throughput =5/33 =0.15

Shortest-Job First (SJF)


This algorithm is assigned to the process that has smallest next CPU processing time,
when the CPU is available. In case of a tie, FCFS scheduling algorithm can be used. It
is originally implemented in a batch-processing environment. SJF relied on a time
estimate supplied with the batch job.
Using SJF scheduling because the shortest length of process will get first executing, the Gantt
chart will be:

P1 P4 P5 P3 P2
0 4 6 12 21 33

Round Robin (RR)


Round Robin (RR) scheduling is a preemptive algorithm that relates the process that
has been waiting the longest. This is one of the oldest, simplest and widely used
algorithms. The round robin scheduling algorithm is primarily used in time-sharing
and a multi-user system environment where the primary requirement is to provide
reasonably good response times and in general to share the system fairly among all
system users. Basically the CPU time is divided into time slices.

Each process is allocated a small time-slice called quantum. No process can run for
more than one quantum while others are waiting in the ready queue. If a process needs
more CPU time to complete after exhausting one quantum, it goes to the end of ready
queue to await the next allocation. To implement the RR scheduling, Queue data
structure is used to maintain the Queue of Ready processes. A new process is added at
the tail of that Queue. The CPU schedular picks the first process from the ready
Queue, Allocate processor for a specified time Quantum. After that time the CPU
schedular will select the next process is the ready Queue.

Using time quantum 1 the Gantt chart for Round Robin scheduling will be as below:

P1 P2 P3 P4 P5 P1 P2 P3 P4 P5 P1 P2 P3 P5 P1 P2 P3

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

P5 P2 P3 P5 P2 P3 P5 P2 P3 P2 P3 P2 P3 P2 P2 P2

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
Ignou Study Helper
www.ignousite.blogspot.com
Priority Based Scheduling or Event-Driven (ED) Scheduling
A priority is associated with each process and the scheduler always picks up the
highest priority process for execution from the ready queue. Equal priority processes
are scheduled FCFS. The level of priority may be determined on the basis of resource
requirements, processes characteristics and its run time behaviour.
A major problem with a priority based scheduling is indefinite blocking of a lost
priority process by a high priority process. In general, completion of a process within
finite time cannot be guaranteed with this scheduling algorithm. A solution to the
problem of indefinite blockage of low priority process is provided by aging priority.
Aging priority is a technique of gradually increasing the priority of processes (of low
priority) that wait in the system for a long time. Eventually, the older processes attain
high priority and are ensured of completion in a finite time.

Gantt Chart:

P5 P4 P3 P2 P1
0 6 8 17 29 33

Q2. Consider the following page-reference string:


1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
How many page faults would occur for following replacement algorithms for a memory with 4
frames? Remember that all frames are initially empty, so your first unique pages will all cost one
fault each.

(i) LRU replacement.


(ii) FIFO replacement.
(iii) Optimal replacement.

Answer:
(I) LRU replacement algorithm:
If the optimal algorithm is not feasible, perhaps an approximation of the optima] algorithm is
possible. The key distinction between the FIFO and OPT algorithms (other than looking backward
versus forward in time) is that the FIFO algorithm uses the time when a page was brought into
memory, whereas the OPT algorithm uses the time when a page is to be used. If we use the
recent past as an approximation of the near future, then we can replace the page that has not
been used for the longest period of time (Figure 9.15). This
approach is the least-recently-used (LRU) algorithm.
Page Reference 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 1 1 1 5 5 5 5 5 3 3 3 3 3 3 3 3 3
Page Frames 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
(4) 3 3 3 3 3 6 6 6 6 6 7 7 7 7 1 1 1 1
4 4 4 4 4 4 1 1 1 1 6 6 6 6 6 6 6
Page Faults (Y/N) Y Y Y Y Y Y Y Y Y Y Y
Page Faults = 11
Ignou Study Helper
Advantages www.ignousite.blogspot.com
Advantages of LRU Page Replacement Algorithm:
1. It is amenable to full statistical analysis.
2. Never suffers from Belady’s anomaly.
Disadvantages
To identify the page to replace, you need to find the minimum time stamp value in all the
registers.

(II) FIFO replacement algorithm:

The simplest page-replacement algorithm is a first-in, first-out (FIFO) algorithm. A FIFO


replacement algorithm associates with each page the time when that page was brought into
memory. When a page must be replaced, the oldest page is chosen. Notice that it is not strictly
necessary to record the time when a page is brought in. We can. create a FIFO queue to hold
all pages in memory. We replace the page at the head of the queue. When a page is brought
into memory, we insert it at the tail of the queue.

Page Reference 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 1 1 1 5 5 5 5 5 3 3 3 3 3 1 1 1 1
Page Frames 2 2 2 2 2 2 6 6 6 6 6 7 7 7 7 7 7 3 3
(4) 3 3 3 3 3 3 2 2 2 2 2 6 6 6 6 6 6 6
4 4 4 4 4 4 1 1 1 1 1 1 2 2 2 2 2
Page Faults (Y/N) Y Y Y Y Y Y Y Y Y Y Y Y Y Y

Page Faults = 14

Advantages of FIFO
1. Obvious improvement over FIFO
2. Allows commonly used pages to stay in queue

Disadvantages of FIFO
.Still suffers from Belady's anomaly

(III) Optimal Page replacement algorithm:

One result of the discovery of Belady's anomaly was the search for an optimal page-
replacement algorithm. An optimal page-replacement algorithm has the lowest page-fault rate of all
algorithms and will never suffer from Belady's anomaly. Such an algorithm does exist and has
been called OPT or MIK.

Page Reference 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 1 1 1 1 1 1 1 1 1 7 7 7 7 1 1 1 1
Page Frames 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
(4) 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4 4 4 5 6 6 6 6 6 6 6 6 6 6 6 6 6
Page Faults (Y/N) Y Y Y Y Y Y Y Y

Page Faults = 8
Ignou Study Helper
www.ignousite.blogspot.com
Advantage
Advantage of the optimal page replacement algorithm is that it has the lowest rate of
occurrence of page faults. Hypothetically, it improves the system performance by reducing
overhead for number of page faults and swapping pages in and out, when a page fault occurs.

Disadvantage
Disadvantage of the optimal page replacement policy is that it is very difficult to implement.
The situation is very similar to that of implementing the SJF algorithm in process management. It
becomes very difficult for an operating system to calculate after what interval a page is to be
referred to.

Q3. Write a monitor solution to the dinning-philosopher problem.

Answer: Five philosophers sit around a circular table. Each philosopher spends his life alternatively
thinking and eating. In the centre of the table is a large bowl of rice. A philosopher needs two chopsticks to
eat. Only 5 chop sticks are available and a chopstick is placed between each pair of philosophers. They
agree that each will only use the chopstick to his immediate right and left. From time to time, a philosopher
gets hungry and tries to grab the two chopsticks that are immediate left and right to him. When a hungry
philosopher has both his chopsticks at the same time, he eats without releasing his chopsticks. When he
finishes eating, he puts down both his chopsticks and starts thinking again.

Here’s a solution for the problem which does not require a process to write another process’s state, and
gets equivalent parallelism.

#define N 5 /* Number of philosphers */


#define RIGHT(i) (((i)+1) %N)
#define LEFT(i) (((i)==N) ? 0 : (i)+1)
typedef enum { THINKING, HUNGRY, EATING } phil_state;
phil_state state[N];
semaphore mutex =1;
semaphore s[N];
void get_forks(int i) {
state[i] = HUNGRY;
while ( state[i] == HUNGRY ) {
P(mutex);
if ( state[i] == HUNGRY &&
state[LEFT] != EATING &&
state[RIGHT(i)] != EATING ) {
state[i] = EATING;
V(s[i]);
}
V(mutex);
P(s[i]);
}
}
void put_forks(int i) {
P(mutex);
state[i]= THINKING;
if ( state[LEFT(i)] == HUNGRY ) V(s[LEFT(i)]);
if ( state[RIGHT(i)] == HUNGRY) V(s[RIGHT(i)]);
V(mutex);
}
void philosopher(int process) {
while(1) {
Ignou Study Helper
think(); www.ignousite.blogspot.com
get_forks(process);
eat();
put_forks();
}
}

Solution to the Dining Philosophers Problem using Monitors


monitor dining-philosophers
{
enum state {thinking, hungry, eating};
state state[5];
condition self[5];
void pickup (int i)
{
state[i] = hungry;
test(i);
if (state[i] != eating)
self[i].wait;
}
void putdown (int i)
{
state[i] = thinking;
test(i+4 % 5);
test(i+1 % 5);
}
void test (int k)
{
if ((state[k+4 % 5] != eating) && (state[k]==hungry)
&& state[k+1 % 5] != eating))
{
state[k] = eating;
self[k].signal;
}
}
init
{
for (int i = 0; i< 5; i++)
state[i] = thinking;
}
}

Condition Variables: If a process cannot enter the monitor it must block itself. This operation is provided by
the condition variables. Like locks and semaphores, the condition has got a wait and a signal function. But it
also has the broadcast signal. Implementation of condition variables is part of a synch.h; it is your job to
implement it.

Q4. Study and implement the Lamport’s Bakery Algorithm for Interprocess synchronization
using C/C++ programming language.
Answer:
Lamport's bakery algorithm: Lamport's bakery algorithm is a computer algorithm devised by
computer scientist Leslie Lamport, which is intended to improve the safety in the usage of shared resources
among multiple threads by means of mutual exclusion.

In computer science, it is common for multiple threads to simultaneously access the same
resources. Data corruption can occur if two or more threads try to write into the same memory location, or if
one thread reads a memory location before another has finished writing into it. Lamport's bakery algorithm
is one of many mutual exclusion algorithms designed to prevent concurrent threads entering critical
sections of code concurrently to eliminate the risk of data corruption.
Ignou Study Helper
www.ignousite.blogspot.com

Analogy: Lamport envisioned a bakery with a numbering machine at its entrance so each customer is
given a unique number. Numbers increase by one as customers enter the store. A global counter displays
the number of the customer that is currently being served. All other customers must wait in a queue until the
baker finishes serving the current customer and the next number is displayed. When the customer is done
shopping and has disposed of his or her number, the clerk increments the number, allowing the next
customer to be served. That customer must draw another number from the numbering machine in order to
shop again.
According to the analogy, the "customers" are threads, identified by the letter i, obtained from a
global variable.
Due to the limitations of computer architecture, some parts of Lamport's analogy need slight
modification. It is possible that more than one thread will get the same number n when they request it; this
cannot be avoided. Therefore, it is assumed that the thread identifier i is also a priority. A lower value of i
means a higher priority and threads with higher priority will enter the critical section first.

Implementation of the algorithm:


The entering variable is known as choosing, and the following conditions apply:

 Words choosing [i] and number [i] are in the memory of process i, and are initially zero.
 The range of values of number [i] is unbounded.
 A process may fail at any time. We assume that when it fails, it immediately goes to its noncritical
section and halts. There may then be a period when reading from its memory gives arbitrary values.
Eventually, any read from its memory must give a value of zero.

Study and implement the Lamport’s Bakery Algorithm for Interprocess synchronization
using C/C++ programming language:

#include(pthread.h)
#include(stdio.h>
#include(unistd.h>
#include (assert.h>
volatile int NUM_THREADS = 10;
volatile int Number[10] = {0};
volatile int count_cs[10] = {0};
volatile int Entering[10] = {0};

int max()
{
int i = 0;
int j = 0;
int maxvalue = 0;
for(i = 0; i < 10; i++)
{
if ((Number[i]) > maxvalue)
{
maxvalue = Number[i];
}
}
return maxvalue;
}
lock(int i)
{
int j;
Entering[i] = 1;
Number[i] = 1 + max();
Entering[i] = 0;
Ignou Study Helper
www.ignousite.blogspot.com
for (j = 1; j <= NUM_THREADS; j++)
{
while (Entering[j]) { } /* Do nothing */
while ((Number[j] != 0) &&
((Number[j] < Number[i]) ||
((Number[j] == Number[i]) && (j < i)))) { }
}
}
unlock(int i) {
Number[i] = 0;
}
void Thread(int i) {
while (1) {
lock(i);
count_cs[i+1] = count_cs[i+1] + 1 ;
//printf("critical section of %d\n", i+1);
unlock(i);
}
}
int main()
{
int duration = 10000;
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t = 0; t < NUM_THREADS; t++){
printf("In main: creating thread %ld\n", t+1);
rc = pthread_create(&threads[t], NULL, Thread, (int)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
usleep(duration*1000);
for(t=0; t < NUM_THREADS; t++)
{
printf("count of thread no %d is %d\n",t+1,count_cs[t+1]);
}
return 0;
}

Q4. Discuss in detail the features, Process management, Memory management, I/O and File
management and Security and Protection in Windows 10 Operating System.
Answer:
Windows 10 features:

1. The Start menu: Windows 10 atones for one of Windows 8’s greatest sins by returning the Start
menu to its rightful spot in the lower left-hand corner of the desktop. But rather than focusing on
desktop apps alone, the Windows 10 Start menu mixes in a dash of the Metro Start screen’s
functionality, sprinkling Live Tiles of Windows 8-style apps next to shortcuts to more traditional PC
software.
You can turn off that Live Tile functionality if you’d like, and even unpin all the Metro apps
from the Start menu, returning it to purely desktop-focused glory. Or you can choose to have the
Start menu expand to the full screen, and resize Metro apps to recreate a more Windows 8-like
experience.
Ignou Study Helper
www.ignousite.blogspot.com
2. Windowed Windows Store apps: As you might have caught onto by now, those reviled
Windows Store apps from Windows 8 haven’t been eradicated—but they have been remolded to fit
desktop sensibilities. In Windows 10, launching a Windows app on your PC opens it in a desktop
window, rather than dumping you into a full-screen app. The windowed apps have a mouse-friendly
toolbar of options across the top, and even alter their interface to best fit the size of the window.

3. Cortana: Cortana, Microsoft’s clever digital assistant on Windows Phone 8.1, makes the jump to
PCs with Windows 10, where she assumes control of the operating system’s search functions.
Cortana will want to access your personal info, then use that info along with her Bing-powered cloud
smarts to intelligently surface information you’re looking for and perform other helpful tasks.

4. The Edge Browser: The new browser in Windows 10, Microsoft Edge includes some very
powerful features. That’s not all it has to offer. It offers, safe, secure and fast browsing experience.
In this post, we will see some of the powerful features of Edge browser.

5. Virtual Desktop: We know there’s a vocal set of people who just love virtual desktops. Having
desktops beyond the limitations of a physical display is a powerful way to organize and quickly
access groups of windows. Virtual desktops aren’t new. In fact, Xerox PARC created one of the
earliest virtual desktop experiences called Rooms back in the 1980s and subsequently made a
version available for Windows 3.x. Microsoft offered the Virtual Desktop Manager as part of the
Windows XP PowerToys and a little while later released the Sysinternals Desktops add-on which
enabled similar functionality. Many other OSes and third-party utilities have also embraced the
power of virtual desktops. Given the growing popularity of this organizational tool, we decided to
build a native virtual desktop experience directly into Windows 10.

Process and Memory Management;


Memory management is becoming a hot topic of discussion as the ubiquitous use of smartphones
and application management is helping previously computer illiterate users become more aware of its
importance. When apps crash, pages fail to load, or the overall operating system of a smartphone begins to
experience unsightly jitters and freezes, many users now intuitively run to their task manager panels to
close apps. While not as sophisticated as PC and software memory management, smartphone users have
a better grasp of the concepts and are now looking to their PCs for the same sorts of principles.
With the Windows 10 Insider program back up and running, the Windows team is giving Insiders
some insight into how Windows 10 is using new memory compressions to tighten up memory management.
In a rather extensive posting found in the Insider Hub (yes, it’s back), the Windows team covers memory
policies and the new Memory Compression built into Windows 10.

File Management in windows 10:


File Explorer is the file management application used by Windows operating systems to browse
folders and files. It provides a graphical interface for the user to navigate and access the files stored in the
computer.
The main way to access the File Explorer is by clicking the folder icon in the Taskbar. After clicking
the icon, the File Explorer window will open.

The initial File Explorer window is comprised of the following sections −

The File Explorer ribbon, which resembles the ribbon featured in Microsoft Office. The ribbon contains
buttons for common tasks to perform with your files and folders.

The Navigation Pane gives you access to your libraries of documents and pictures, as well as your storage
devices. It also features frequently used folders and network devices.

The Frequent folders section on the right features the folders you’ve worked with recently to allow for quick
access to them.
Ignou Study Helper
www.ignousite.blogspot.com
The Recent files section in the lower part of the window features files and documents that you’ve opened
recently.

Windows 10 – Security:
Windows 10 features a series of tools to help you protect your computer from threats like viruses
and other malware. The three main security tools are −
>User Account Control
>Windows Defender
>Windows Firewall

User Account Control: The Windows User Account Control is a tool that warns you when someone or
something attempts to change your computer system settings. When this happens, the screen will alert you until
an Administrator can confirm the change. This helps protect your computer against accidental changes or
malicious software altering your settings.
Initially, this User Account Control is set at a moderate to high level, which means it will notify you only
when an application tries to make changes to your computer. However, you can change this setting to your
desired level

Windows Defender: Windows Defender is an antivirus and malware protection included in your operating
system. It allows you to scan your computer for malicious software, while also checking each file or program
you open.
To configure Windows Defender, follow these steps −

Step 1 − Go to SETTINGS and select Update & security.

Step 2 − In the UPDATE & SECURITY window, select Windows Defender.

Here you can customize settings like turning off real-time protection or activating cloudbased
protection, which allows Defender to send Microsoft information about security threats it finds.

Windows Firewall: Windows Firewall prevents unauthorized access from outside to get into your computer. By
default, it is turned on to protect your computer and your network.
If you want to customize your Firewall, follow these steps −

Step 1 − Open the Control Panel by searching for it in the Search bar.

Step 2 − When the Control Panel is open, choose Windows Firewall.


Step 3 − In the Windows Firewall window, you can customize the settings of it by turning it on or off
or choosing when to protect your computer.

Potrebbero piacerti anche