OS File Final
OS File Final
2) pwd: It stands for Print Working Directory. It prints the path of the working directory,
starting from the root.
4) ls: It lists directory contents of files and directories. It has many options such as:
a) -l: to display long list
b) -t: to sort by modification time
c) -s: to sort by size
d) -h: to list files in human readable format
e) -r: to reverse the order
7) vi: It is the default editor that comes with the UNIX operating system is called vi (visual
editor). Using vi editor, we can edit an existing file or create a new file from scratch. we can
also use this editor to just read a text file.
8) cat: It reads data from the file and gives their content as output. It dumps an entire file to
standard output. It is good for displaying short, simple files.
10) head: It prints the top N number of data of the given input. By default, it prints the first
10 lines of the specified files. If more than one file name is provided then data from each file
is preceded by its file name.
11) tail: It prints the last N number of data of the given input. By default, it prints the last 10
lines of the specified files. If more than one file name is provided then data from each file is
preceded by its file name.
13) mv: It stands for move. mv is used to move one or more files or directories from one
place to another in a file system like UNIX. It has two distinct functions:
a) It renames a file or folder.
b) It moves a group of files to a different directory.
15) wc: wc stands for word count. As the name implies, it is mainly used for counting
purpose.
a) It is used to find out number of lines, word count, byte and characters count in the
files
specified in the file arguments.
b) By default it displays four-columnar output.
c) First column shows number of lines present in a file specified, second column
shows
number of words present in the file, third column shows number of characters
present in
file and fourth column itself is the file name which are given as argument.
16) ps: it allows viewing information related with the processes on a system. It stands for
“Process Status”.
20) finger: Finger command is a user information lookup command which gives details of all
the users logged in.
23) whoami: it displays the username of the current user when this command is invoked.
ii)
ii)
PERFORMANCE –
#include <iostream>
using namespace std;
class process
{
public:
int id;
int arrival;
int burst;
int finish;
int tat;
int wait;
process()
{
arrival = 0;
burst = 0;
id = 0;
}
// sorting IDs
temp = p[j].id;
p[j].id = p[j + 1].id;
p[j + 1].id = temp;
}
}
}
}
int i;
for (i = 0; i < n; i++)
{
int a, b;
cout << "Enter arrival time for process P" << i + 1 << ":";
cin >> a;
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> b;
p[i] = process(a, b, i);
cout << "\n";
}
process f;
f.sort(p, n);
f.calc(p, n);
f.display(p, n);
return 0;
}
#include <iostream>
using namespace std;
class process
{
public:
int id;
int arrival;
int burst;
int finish;
int tat;
int wait;
process()
{
arrival = 0;
burst = 0;
id = 0;
}
// sorting IDs
temp = p[j].id;
p[j].id = p[j + 1].id;
p[j + 1].id = temp;
}
}
}
}
int main()
{
int n = 0;
cout << "Enter no of processes: ";
cin >> n;
process *p = new process[n];
int i;
for (i = 0; i < n; i++)
{
int a, b;
cout << "Enter arrival time for process P" << i + 1 << ":";
cin >> a;
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> b;
p[i] = process(a, b, i);
cout << "\n";
}
process f;
f.sort(p, n);
f.calc(p, n);
f.display(p, n);
return 0;
}
class process
{
public:
int id;
int burst;
int arrival;
process()
{
arrival = 0;
burst = 0;
id = 0;
}
if (check == false)
{
t++;
continue;
}
remain[shortest]--;
minimum = remain[shortest];
if (minimum == 0)
minimum = INT_MAX;
if (remain[shortest] == 0)
{
complete++;
check = false;
finish = t + 1;
wait[shortest] = finish -
p[shortest].burst -
p[shortest].arrival;
if (wait[shortest] < 0)
wait[shortest] = 0;
}
t++;
}
}
findWaitingTime(p, n, wait);
int main()
{
int n = 0;
cout << "Enter no of processes: ";
cin >> n;
process *p = new process[n];
int i;
for (i = 0; i < n; i++)
{
int a, b;
cout << "Enter arrival time for process P" << i + 1 << ":";
cin >> a;
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> b;
p[i] = process(a, b, i);
cout << "\n";
}
findavgTime(p, n);
return 0;
}
int main()
{
int i, n, finish = 0, count = 0, a, quantum, wait = 0, tat = 0, arri-
val[10], burst[10], temp[10];
cout << "Total number of process in the system: ";
cin >> n;
a = n;
for (int i = 0; i < n; i++)
{
int a, b;
cout << "Enter arrival time for process P" << i + 1 << ":";
cin >> arrival[i];
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> burst[i];
temp[i] = burst[i];
cout << "\n";
}
cout << "Enter the Time Quantum for the process: ";
cin >> quantum;
cout << "Process\tArrival\tBurst\tFinish\tTurn Around\tWaiting\n";
for (finish = 0, i = 0; a != 0;)
{
if (temp[i] <= quantum && temp[i] > 0)
{
finish = finish + temp[i];
temp[i] = 0;
count = 1;
#define totalprocess 4
class process
{
public:
int arrival, burst, priority, id;
};
process p[50];
service[0] = p[0].arrival;
wait[0] = 0;
void findgc()
{
int wait[50], tat[50];
get_wt_time(wait);
get_tat_time(tat, wait);
start[0] = p[0].arrival;
finish[0] = start[0] + tat[0];
int main()
{
for (int i = 0; i < totalprocess; i++)
{
cout << "Enter arrival time for process P" << i + 1 << ":";
findgc();
return 0;
}
int i;
for (i = 0; i < n; i++)
{
int a, b;
cout << "Enter arrival time for process P" << i + 1 << ":";
cin >> arrival[i];
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> burst[i];
cout << "Enter priority for process P" << i + 1 << ":";
cin >> priority[i];
cout << "\n";
}
int x[n];
class bankers
{
private:
int allocated[MAX][MAX], a[MAX][MAX], b[MAX][MAX], available[MAX];
int n, resources, k, result[MAX], id, work[MAX], finish[MAX];
public:
bankers()
{
k = 0;
for (int i = 0; i < MAX; i++)
{
for (int j = 0; j < MAX; j++)
{
allocated[i][j] = 0;
a[i][j] = 0;
b[i][j] = 0;
}
available[i] = 0;
result[i] = 0;
finish[i] = 0;
}
}
void input()
{
int i, j;
cout << "Enter the number of processes:";
cin >> n;
cout << "Enter the number of resources:";
cin >> resources;
cout << "Enter the allocated resources for each process: " << endl;
void method()
{
int i = 0, j, flag;
while (1)
{
if (finish[i] == 0)
{
id = search(i);
if (id != -1)
{
result[k++] = i;
finish[i] = 1;
for (j = 0; j < resources; j++)
{
available[j] = available[j] + allocated[i][j];
}
flag = 1;
for (j = 0; j < resources; j++)
work[j] = available[j];
if (flag == 0)
break;
else
i = 0;
}
}
}
int search(int i)
{
int j;
for (j = 0; j < resources; j++)
if (b[i][j] > available[j])
return -1;
return 0;
}
void display()
{
int i, j;
cout << endl
<< "OUTPUT:";
cout << endl
<< "========";
cout << endl
<< "PROCESS\t ALLOCATED\t MAXIMUM\t NEED";
for (i = 0; i < n; i++)
{
cout << "\nP" << i + 1 << "\t ";
for (j = 0; j < resources; j++)
{
cout << allocated[i][j] << " ";
}
cout << "\t ";
for (j = 0; j < resources; j++)
int main()
{
bankers b;
b.input();
b.method();
b.display();
}
int main()
{
int str[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 0, 3, 2, 1, 2, 0, 1, 7,
0, 1};
int faults = 0;
int frames = 3;
int i, j, s, pages;
int main()
{
int q[20], p[50], c = 0, c1, d, f, i, j, k = 0, n, r, t, b[20], c2[20];
cout << "Enter no of pages:";
cin >> n;
cout << "Enter the reference string:";
for (i = 0; i < n; i++)
cin >> p[i];
cout << "Enter no of frames:";
cin >> f;
q[k] = p[k];
cout << "\n\t" << q[k] << "\n";
c++;
k++;
for (i = 1; i < n; i++)
{
c1 = 0;
for (j = 0; j < f; j++)
{
if (p[i] != q[j])
c1++;
}
if (c1 == f)
{
c++;
if (k < f)
{
q[k] = p[i];
k++;
for (j = 0; j < k; j++)
cout << "\t" << q[j];
cout << "\n";
}
else
int main()
{
int no_of_frames, no_of_pages, frames[10], pages[30], temp[10], flag1,
flag2, flag3, i, j, k, pos, max, faults = 0;
if (flag1 == 0)
{
for (j = 0; j < no_of_frames; ++j)
{
if (frames[j] == -1)
{
faults++;
frames[j] = pages[i];
flag2 = 1;
break;
}
}
}
if (flag2 == 0)
{
flag3 = 0;
if (flag3 == 0)
{
max = temp[0];
frames[pos] = pages[i];
faults++;
}
return 0;
}
int n;
int head;
int complete[N];
int str[N];
void sstf()
{
int movement = 0;
for (int i = 0; i < n; i++)
{
int index = 0;
int shortest = INT_MAX;
for (int k = 0; k < n; k++)
{
if (abs(head - str[k]) < shortest && !complete[k])
{
index = k;
shortest = abs(head - str[k]);
int main()
{
cout << "Queue Size: ";
cin >> n;
cout << "Enter the queue of disk positions to be read: ";
for (int i = 0; i < n; i++)
cin >> str[i];
cout << "Initial Head Position: ";
cin >> head;
sstf();
return 0;
}
if (GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS
*)&pmc, sizeof(pmc)))
{
cout << "File name: " << pmc.thisFile << endl;
cout << "Size used: " << pmc.PrivateUsage << endl;
}
else
{
cout << "Failed to retrieve memory usage. Error code: " << GetLastEr-
ror() << endl;
}
return 0;
}
int main()
{
int i = 0;
int status;
return 0;
}