Os Edited
Os Edited
INSTITUTE OF TECHNOLOGY
OPERATING SYSTEM
Group Assignment (I) & (II)
NAME: ID. NO :
1. AREGAHAGN DESTA ……………………........ NSR/329/13
2. ABDI TAJU………………………………………...NSR/020/13
3. NIHAL MUSA.........................................................NSR/1910/13
INSTRUCTOR: Mr DAWIT
#include<iostream>
// main function
int main()
{
// process ids
int processes[] = { 1, 2, 3, 4};
int n = sizeof processes / sizeof processes[0];
findAverageTime(processes, n, burst_time);
return 0;
}
Output:
Processes Burst time Waiting time Turn around time
1 21 0 21
2 3 21 24
3 6 24 30
4 2 30 32
Average waiting time = 18.75
Average turn around time = 26.75
#include<bits/stdc++.h>
struct Process
{
int pid; // process ID
int bt; // burst Time
};
/*
this function is used for sorting all
processes in increasing order of burst time
*/
bool comparison(Process a, Process b)
{
return (a.bt < b.bt);
}
// main function
int main()
{
Process proc[] = {{1, 21}, {2, 3}, {3, 6}, {4, 2}};
int n = sizeof proc / sizeof proc[0];
findAverageTime(proc, n);
return 0;
}
Output:
Order in which process gets executed
4231
Processes Burst time Waiting time Turn around time
4 2 0 2
2 3 2 5
3 6 5 11
1 21 11 32
Round Robin scheduling algorithm is one of the most popular scheduling algorithm
which can actually be implemented in most of the operating systems. This is the pre-
emptive version of first come first serve scheduling. The Algorithm focuses on Time
Sharing. In this algorithm, every process gets executed in a cyclic way. A certain time
slice is defined in the system which is called time quantum. Each process present in
the ready queue is assigned the CPU for that time quantum, if the execution of the
process is completed during that time then the process will terminate else the process
will go back to the ready queue and waits for the next turn to complete the execution.
//Learnprogramo - programming made Simple
// C++ program for implementation of RR scheduling
#include<iostream>
using namespace std;
// Function to find the waiting time for all
// processes
void findWaitingTime(int processes[], int n,
int bt[], int wt[], int quantum)
{
// Make a copy of burst times bt[] to store remaining
// burst times.
int rem_bt[n];
for (int i = 0 ; i < n ; i++)
rem_bt[i] = bt[i];
int t = 0; // Current time
// Keep traversing processes in round robin manner
// until all of them are not done.
while (1)
{
bool done = true;
// Traverse all processes one by one repeatedly
for (int i = 0 ; i < n; i++)
{
// If burst time of a process is greater than 0
// then only need to process further
if (rem_bt[i] > 0)
{
done = false; // There is a pending process
if (rem_bt[i] > quantum)
{
// Increase the value of t i.e. shows
// how much time a process has been processed
t += quantum;
// Decrease the burst_time of current process
// by quantum
rem_bt[i] -= quantum;
}
// If burst time is smaller than or equal to
// quantum. Last cycle for this process
else
{
// Increase the value of t i.e. shows
// how much time a process has been processed
t = t + rem_bt[i];
// Waiting time is current time minus time
// used by this process
wt[i] = t - bt[i];
// As the process gets fully executed
// make its remaining burst time = 0
rem_bt[i] = 0;
}
}
}
// If all processes are done
if (done == true)
break;
}
}
// Function to calculate turn around time
void findTurnAroundTime(int processes[], int n,
int bt[], int wt[], int tat[])
{
// calculating turnaround time by adding
// bt[i] + wt[i]
for (int i = 0; i < n ; i++)
tat[i] = bt[i] + wt[i];
}
// Function to calculate average time
void findavgTime(int processes[], int n, int bt[],
int quantum)
{
int wt[n], tat[n], total_wt = 0, total_tat = 0;
// Function to find waiting time of all processes
findWaitingTime(processes, n, bt, wt, quantum);
// Function to find turn around time for all processes
findTurnAroundTime(processes, n, bt, wt, tat);
// Display processes along with all details
cout << "Processes "<< " Burst time "
<< " Waiting time " << " Turn around time\n";
// Calculate total waiting time and total turn
// around time
for (int i=0; i<n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
cout << " " << i+1 << "\t\t" << bt[i] <<"\t "
<< wt[i] <<"\t\t " << tat[i] <<endl;
}
cout << "Average waiting time = "
<< (float)total_wt / (float)n;
cout << "\nAverage turn around time = "
<< (float)total_tat / (float)n;
}
int main()
{
// process id's
int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];
// Burst time of all processes
int burst_time[] = {10, 5, 8};
// Time quantum
int quantum = 2;
findavgTime(processes, n, burst_time, quantum);
return 0;
}
output:
int n, m, i, j, k;
n = 5; // Number of processes
m = 3; // Number of resources
int alloc[5][3] = { { 0, 1, 0 }, // P0 // Allocation Matrix
{ 2, 0, 0 }, // P1
{ 3, 0, 2 }, // P2
{ 2, 1, 1 }, // P3
{ 0, 0, 2 } }; // P4
int flag = 0;
for (j = 0; j < m; j++) {
if (need[i][j] > avail[j]){
flag = 1;
break;
}
}
if (flag == 0) {
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}
int flag = 1;
if(flag==1)
{
cout << "Following is the SAFE Sequence" << endl;
for (i = 0; i < n - 1; i++)
cout << " P" << ans[i] << " ->";
cout << " P" << ans[n - 1] <<endl;
}
return (0);
}
Output
Following is the SAFE Sequence
P1 -> P3 -> P4 -> P0 -> P2
#include<bits/stdc++.h>
using namespace std;
int allocation[10][3],need[10][3],Max[10][3],available[10][3];
int p,current[3];
bool executed[10],come;
void IMP(){
come=false;
for (int i = 0; i < 10; ++i)
{
executed[i]=false;
}
}
void Calculate(){
IMP();
int i,j;
for (i = 0; i < p; ++i)
{
for (j = 0; j < p; ++j)
{
while(executed[j] && j<p-1){
j++;
}
if (need[j][0]<=current[0]&&need[j][1]<=current[1]&&need[j]
[2]<=current[2])
{
if (!executed[j])
{
executed[j]=true;
current[0]+=allocation[j][0];current[1]+=allocation[j]
[1];current[2]+=allocation[j][2];
cout<<"\nProcess P"<<j+1;
cout<<"\nCurrent: "<<current[0]<<" "<<current[1]<<"
"<<current[2]<<"\n";
cout<<"\nProcess executed without deadlock";
come=true;
break;
}
}
}
if (!come)
{
cout<<"\n Dead lock\n\n";
break;
}else{
come=false;
}
}
}
Protection:
Protection deals with the access to the system resources. It determines that what
files can be accessed or permeated by a special user. The protection of the system
should confirm the approval of the process and users. Due to this, these licensed
users and processes will care for the central processing unit, memory and
alternative sources. The protection mechanism ought to provide a path for
specifying the controls to be obligatory, beside how of implementing them.
Example of protection can be given from the security, any organization will have
many departments below that several staff operate. the assorted departments will
share frequent info with one another however not sensitive info. So, completely
different employees have different access rights the info in step with that they
will access the define data.
S.No Comparison based on Security Protection
Protection problem - ensure that each object is accessed correctly and only by
those processes that are allowed to do so.
To ensure that each shared resource is used only in accordance with system
policies, which may be set either by system designers or by system
administrators.
To ensure that errant programs cause the minimal amount of damage possible.
Note that protection systems only provide the mechanisms for enforcing
policies and ensuring reliable systems. It is up to administrators and users to
implement those mechanisms effectively.
Principles of Protection
Programs, users and systems should be given just enough privileges to perform
their tasks
The principle of least privilege dictates that programs, users, and systems be
given just enough privileges to perform their tasks.
This ensures that failures do the least amount of harm and allow the least of
harm to be done.
Typically each user is given their own account, and has only enough privilege
to modify their own files.
The root account should not be used for normal day to day activities – The
System Administrator should also have an ordinary account, and reserve use of
the root account for only those tasks which need the root privileges
2. Explain the following security problems (violations of security)
independently?
Masquerading(man in the middle attack)
A masquerade attack is an attack that uses a fake identity, such as a network
identity, to gain unauthorized access to personal computer information through
legitimate access identification. If an authorization process is not fully protected,
it can become extremely vulnerable to a masquerade attack.
Theft of Services
Theft of services is a crime that refers to using a service without paying for it.
This is a common charge among people who do not have lengthy criminal
records, because there are many ways to commit theft of service without even
realizing it. Many people charged with theft of service are law-abiding citizens,
or people who simply made a mistake. Fortunately, the charge is often dismissed,
and can be expunged from one’s criminal record.
Theft of service is usually misdemeanor, but if the service was worth a lot of
money, as with medical services or construction work, it could be considered a
felony. However, there are some valid reasons not to pay for services, in which
case a theft of service charge may be successfully contested. For very minor
offenses, it may even be dismissed.
A DoS or DDoS attack is analogous to a group of people crowding the entry door
of a shop, making it hard for legitimate customers to enter, thus disrupting trade.
Computer is used to flood a server with TCP and UDP packets. A DDoS attack is
where multiple systems target a single system with a DoS attack.
The following is a breakdown of the three key concepts that form the CIA triad:
Reply attack
A logic bomb
Is a set of instructions in a program carrying a malicious payload that can attack
an operating system, program, or network. It only goes off after certain
conditions are met. A simple example of these conditions is a specific date or
time. A more complex example is when an organization fires an employee and
logs their dismissal in their system.
A logic bomb usually carries a computer virus or a computer worm. Even though
some people use the two terms interchangeably, they’re not the types of malware.
Let’s understand the worm vs virus debate better:
Trojan horse
A Trojan Horse (Trojan) is a type of malware that disguises itself as legitimate
code or software. Once inside the network, attackers are able to carry out any
action that a legitimate user could perform, such as exporting files, modifying
data, deleting files or otherwise altering the contents of the device. Trojans may
be packaged in downloads for games, tools, apps or even software patches. Many
Trojan attacks also leverage social engineering tactics, as well
as spoofing and phishing, to prompt the desired action in the user
Spyware
Spyware (a portmanteau for spying software) is software with malicious
behaviour that aims to gather information about a person or organization and
send it to another entity in a way that harms the user—for example, by violating
their privacy or endangering their device's security. This behaviour may be
present in malware as well as in legitimate software. Websites may engage in
spyware behaviours like web tracking. Hardware devices may also be affected.
[1] Spyware is frequently associated with advertising and involves many of the
same issues. Because these behaviors are so common, and can have non-harmful
uses, providing a precise definition of spyware is a difficult task.[2]
It only requires a single key for both It requires two keys, a public key and a
encryption and decryption private key, one to encrypt and the
other one to decrypt.
The size of cipher text is the same or The size of cipher text is the same or
smaller than the orjinal plain text larger than the original plain tex
The length of key used is 128 or 256 The length of key used is 2048 or
bits higher
Security is less as only one key is used It is more secure as two keys are used
for both encryption and decryption here- one for encryption and the other
purpose. for decryption