Os Final Record
Os Final Record
No:1
DATE : BASICS OF UNIX COMMANDS
AIM:
TostudyandexecuteUnixcommands.
GENERALCOMMANDS
Command Function
Date Used to display the current system date and time.
date+%D Displays date only
date+%T Displays time only
date+%Y Displays the year part of date
date+%H Displays the hour part of time
Cal Calendar of the current month
Calyear Displays calendar for all months of the specified year
calmonthyear Displays calendar for the specified month of the year
Who Login detailsof all users such as their IP,TerminalNo,
User name,
whoami Used to display the login details of the user
Tty Used to display the terminal name
Uname Displays the Operating System
uname–r Shows version number of the OS(kernel).
uname–n Displays domain name of the server
echo"txt" Displays the given text on the screen
echo$HOME Displays the user's home directory
Bc Basic calculator.Press Ctrl+d to quit
Lpfile Allows the user to spool a job along with others in a print queue.
DIRECTORYCOMMANDS
Command Function
Pwd Path of the present working directory
Mkdirdir A directory is created in the given name under the current
Directory
mkdirdir1dir2 A number of sub-directories can be created under one stroke
cdsubdir Change Directory. If the subdir starts with / then path starts from
root(absolute) otherwise from current working directory.
FILECOMMANDS
Command Function
cat>filename To create a file with some contents. To end typing press
Ctrl+d.
The > symbol means redirecting out put to a file.(<forinput)
catfilename Displays the file contents.
cat>>filename Used to append contents to a file
cpsrcdes Copy files to given location. If already exists, it
will be Overwritten
cp–isrcdes Warns the user prior to over writing the destination file
cp–rsrcdes Copies the entire directory, all its sub-directories and files.
mvoldnew To rename an existing file or directory. –i option
can also be Used
mvf1f2f3dir To move a group offiles to a directory.
mv–voldnew Display name of each file as it is moved.
Rmfile Used to delete a file or group of files.– I option can also be used
rm* To delete all the files in the directory.
rm–r* Deletes all files and sub-directories
rm–f* To forcibly remove even write-protected files
Ls Lists all files and subdirectories(bluecolored) insorted
manner.
Lsname To check whether a file or directory exists.
lsname* Short-hand notation to list out filenames of a specific pattern.
ls–a Lists all files including hidden files(files beginning with.)
ls–xdirname To have specific list in go f a directory.
ls–R Recursive list in go fall files in thes ubdirectories
ls–l Longl isting showing file access rights(read/write/execute-rwx
foruser/group/others-ugo).
cmpfile1file2 Used to compare two files. Displays nothing if files
are identical.
Wcfile It produces a statisticsoflines(l),words(w),andcharacters(c).
chmodpermfile Changes permission for the specified file. (r=4, w=2,x=1)
chmod 740 file sets all rights for user, read only for groups
and no rights for others
OUTPUT
GENERAL COMMANDS
[student ~]date
Sat May 16 06:10:34 UTC 2020
[student~]date +%D
05/16/20
[student~]date +%T
10:13:11
[student~]date +%Y
2020
[student~]date +%H
10
[student~]cal
May 2020
Su Mo Tu We Th Fr
1 Sa
2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
[student~]cal 2020
2020
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr
Sa Su Mo Tu We Th Fr Sa
1 2 3 4
1 1 2 3 4 5 6 7
5 6 7 8 9 10 11 2 3 4 5 6 7
8 8 9 10 11 12 13 14
12 13 14 15 16 17 18 9 10 11 12 13 14
15 15 16 17 18 19 20 21
19 20 21 22 23 24 25 16 17 18 19 20 21
22 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr
Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1
2 1 2 3 4 5 6
5 6 7 8 9 10 11 3 4 5 6 7 8
9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15
16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22
23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29
30 28 29 30
31
October November
December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr
Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6
7 1 2 3 4 5
4 5 6 7 8 9 10 8 9 10 11 12 13
14 6 7 8 9 10 11 12
11 12 13 14 15 16 17 15 16 17 18 19 20
21 13 14 15 16 17 18 19
18 19 20 21 22 23 24 22 23 24 25 26 27
28 20 21 22 23 24 25 26
25 26 27 28 29 30 31 29 30
27 28 29 30 31
[student~]cal 2020
July 2020
Su Mo Tu We
1 Th
2 Fr
3 Sa
4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
[student~]who
studentpts/1 May 16 10:05 (172.16.1.14)
[student~]who am i
studentpts/1 May 16 10:05 (172.16.1.14)
[student~]tty
/dev/pts/1 [student~]uname Linux
[student~]echo "hello"
hello
[student~]echo $HOME
/home/student
DIRECTORY COMMANDS
[student~]$pwd
/home/student
[student~]mkdirsan [student~]mkdir s1 s2[student~]ls
s1 s2 san [student~]cd s1 [student s1]$ cd / [student /]$ cd . . [student /]$rmdir s1 [student ~]$ ls
s2 san
FILE COMMANDS
[student ~]$ cat>test
hi welcome operating systems lab
[student ~]$ cat test
hi welcome operating systems lab
AIM:
ALGORITHM:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
pid = fork();
if (pid < 0) {
perror("Fork failed");
exit(1);
}
else if (pid > 0) {
// Parent process
wait(NULL);
printf("\nParent Process:\n");
printf("\n\tParent Process ID: %d\n", getpid());
return 0;
}
OUTPUT:
Thus the program for process management was written and successfully executed.
EX.NO.3A: IMPLEMENTATION OF FCFS SCHEDULING ALGORITHM
DATE:
AIM
To write a C program to implement First Come First Serve scheduling algorithm.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input process and their burst time.
Step 3: Sort the processes based on order in which it requests CPU.
Step 4: Compute the waiting time and turnaround time for each process.
Step 5: Calculate the average waiting time and average turnaround time.
Step 6: Print the details about all the processes.
Step 7: Stop the program.
PROGRAM :
#include<stdio.h>
Void main()
{
int bt[50],wt[80],at[80],wat[30],ft[80],tat[80];
int i,n;
float awt,att,sum=0,sum1=0;
charp[10][5];
printf("\nenter the number of process ");
scanf("%d",&n);
printf("\nEnter the process name and burst-time:");
for(i=0;i<n;i++)scanf("%s%d",p[i],&bt[i]);
printf("\nEnter the arrival- time:");
for(i=0;i<n;i++)
scanf("%d",&at[i]);
wt[0]=0;
for(i=1;i<=n;i++)
wt[i]=wt[i-1]+bt[i-1];
ft[0]=bt[0]; for(i=1;i<=n;i++)
ft[i]=ft[i-1]+bt[i];
printf("\n\n\t\t\tGANTT CHART\n");
printf("\n \n");
for(i=0;i<n;i++)
printf("|\t%s\t",p[i]);
printf("|\t\n");
printf("\n \n");
printf("\n");
for(i=0;i<n;i++)
printf("%d\t\t",wt[i]);
printf("%d",wt[n]+bt[n]); printf("\n \n");
printf("\n"); for(i=0;i<n;i++)
wat[i]=wt[i]-at[i]; for(i=0;i<n;i++)
tat[i]=wat[i]-at[i];
printf("\n FIRST COME FIRST SERVE\n");
printf("\n Process Burst-time Arrival-time Waiting-time Finish-time Turnaround-time\n");
for(i=0;i<n;i++)
printf("\n\n %d%s \t %d\t\t %d \t\t %d\t\t %d
\t\t%d",i+1,p[i],bt[i],at[i],wat[i],ft[i],tat[i]);
for(i=0;i<n;i++)
sum=sum+wat[i];
awt=sum/n;
for(i=0;i<n;i++)
sum1=sum1+bt[i]+wt[i];
att=sum1/n;
printf("\n\nAverage waiting time:%f",awt);
printf("\n\nAverage turnaround time:%f",att);
}
}
OUTPUT:
AIM:
ALGORITHM:
#include <stdio.h>
int main()
{
// Matrix for storing Process Id, Burst
// Time, Average Waiting Time & Average
// Turn Around Time.
int A[100][4];
int i, j, n, total = 0, index, temp;
float avg_wt, avg_tat;
printf("Enter number of process: ");
scanf("%d", &n);
printf("Enter Burst Time:\n");
// User Input Burst Time and alloting Process Id.
for (i = 0; i< n; i++) {
printf("P%d: ", i + 1);
scanf("%d", &A[i][1]);
A[i][0] = i + 1;
}
// Sorting process according to their Burst Time.
for (i = 0; i< n; i++) {
index = i;
for (j = i + 1; j < n; j++)
if (A[j][1] < A[index][1])
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
}
A[0][2] = 0;
// Calculation of Waiting Times
for (i = 1; i< n; i++) {
A[i][2] = 0;
for (j = 0; j <i; j++)
A[i][2] += A[j][1];
total += A[i][2];
}
avg_wt = (float)total / n;
total = 0;
printf("P BT WT TAT\n");
// Calculation of Turn Around Time and printing the
// data.
for (i = 0; i< n; i++) {
A[i][3] = A[i][1] + A[i][2];
total += A[i][3];
printf("P%d %d %d %d\n", A[i][0],
A[i][1], A[i][2], A[i][3]);
}
avg_tat = (float)total / n;
printf("Average Waiting Time= %f", avg_wt);
printf("\nAverage Turnaround Time= %f", avg_tat);
}
OUTPUT:
RESULT:
AIM:
ALGORITHM:
void main()
{
// initlialize the variable name
int i, NOP, sum=0,count=0, y, quant, wt=0, tat=0, at[10], bt[10], temp[10];
float avg_wt, avg_tat;
clrscr();
printf("\n\n Round Robin Schedulling algorithm");
printf("\n *************************************\n");
printf(" \n Total number of process in the system: ");
scanf("%d", &NOP);
y = NOP; // Assign the number of process to variable y
// Use for loop to enter the details of the process like Arrival time and the Burst Time
for(i=0; i<NOP; i++)
{
printf("\n Enter the Arrival and Burst time of the Process[%d]\n", i+1);
printf(" Arrival time is: \t"); // Accept arrival time
scanf("%d", &at[i]);
printf(" \nBurst time is: \t"); // Accept the Burst time
scanf("%d", &bt[i]);
temp[i] = bt[i]; // store the burst time in temp array
}
// Accept the Time qunat
printf("Enter the Time Quantum for the process: \t");
scanf("%d", &quant);
// Display the process No, burst time, Turn Around Time and the waiting time
printf("\n Process No \t\t Burst Time \t\t TAT \t\t Waiting Time ");
for(sum=0, i = 0; y!=0; )
{
if(temp[i] <= quant && temp[i] > 0) // define the conditions
{
sum = sum + temp[i];
temp[i] = 0;
count=1;
}
else if(temp[i] > 0)
{
temp[i] = temp[i] - quant;
sum = sum + quant;
}
if(temp[i]==0 && count==1)
{
y--; //decrement the process no.
printf("\nProcess No[%d] \t\t %d\t\t\t\t %d\t\t\t %d", i+1, bt[i], sum-at[i], sum-at[i]-bt[i]);
wt = wt+sum-at[i]-bt[i];
tat = tat+sum-at[i];
count =0;
}
if(i==NOP-1)
{
i=0;
}
else if(at[i+1]<=sum)
{
i++;
}
else
{
i=0;
}
}
// represents the average waiting time and Turn Around time
avg_wt = wt * 1.0/NOP;
avg_tat = tat * 1.0/NOP;
printf("\n Average Turn Around Time: \t%f", avg_wt);
printf("\n Average Waiting Time: \t%f", avg_tat);
getch();
}
OUTPUT:
RESULT:
AIM:
ALGORITHM:
#include<stdio.h>
#include<string.h>
void main()
{
int bt[30],pr[30],np; intwt[30],tat[30],wat[30],at[30],ft[30];
int i,j,x,z,t;
float sum1=0,sum=0,awt,att;
charp[5][9],y[9];
printf("\nenter the number of process");
scanf("%d",&np);
printf("\nEnter the process,burst-time and priority:");
for(i=0;i<np;i++)
scanf("%s%d%d",p[i],&bt[i],&pr[i]);
printf("\nEnter the arrival-time:");
for(i=0;i<np;i++)
scanf("%d",&at[i]);
for(i=0;i<np;i++)
for(j=i+1;j<np;j++)
{
if(pr[i]>pr[j])
{
x=pr[j]; pr[j]=pr[i]; pr[i]=x; strcpy(y,p[j]);
strcpy(p[j],p[i]);
strcpy(p[i],y);
z=bt[j]; b t[j]=bt[i]; bt[i]=z;
}
} wt[0]=0;
for(i=1;i<=np;i++)
wt[i]=wt[i-1]+bt[i-1];
ft[0]=bt[0]; for(i=1;i<np;i++)
ft[i]=ft[i-1]+bt[i]; printf("\n\n\t\tGANTT CHART\n");
printf("\\n");
for(i=0;i<np;i++)
printf("|\t%s\t",p[i]);
printf("|\t\n");
printf("\n \n");
printf("\n"); for(i=0;i<=np;i++)
printf("%d\t\t",wt[i]);
printf("\n \n");
printf("\n"); for(i=0;i<np;i++)
wat[i]=wt[i]-at[i]; for(i=0;i<np;i++)
tat[i]=wat[i]-at[i]; printf("\nPRIORITY SCHEDULING:\n");
printf("\nProcess Priority Burst-time Arrival-time Waiting-time Turnaround-time");
for(i=0;i<np;i++)
printf("\n\n%d%s\t%d\t\t%d\t\t%d\t%d\t\t%d",i+1,p[i],pr[i],bt[i],a t[i],wt[i],tat[i]);
for(i=0;i<np;i++)
sum=sum+wat[i]; awt=sum/np; for(i=0;i<np;i++)
sum1=sum1+tat[i]; att=sum1/np;
printf("\n\nAverage waiting time:%f",awt); printf("\n\nAverageturnaroundtime is:%f",att);
}
OUTPUT:
GANTT CHART
| p3 | p2 | p1 |
0
5
9
12
PRIORITY SCHEDULING:
Process Priority Burst-time Arrival-time Waiting-time Turnaround-time
p3 1 5 0 0 0
p2 2 4 1 5 3
p1 3 3 2 9 5
Average waiting time: 3.666667 Average turnaround time is: 2.666667
RESULT:
AIM:
ALGORITHM:
Step 1: Start
Step 2: Define the number of philosophers
Step 3: Declare one thread per philosopher
Step 4: Declare one semaphore (represent chopsticks) per philosopher
Step 5: When a philosopher is hungry See if chopsticks on both sides are free Acquire both
chopsticks
Eat Restore the chopstick If chopsticks aren‟t free
Step 6: Wait till they are available
Step 7: Stop
PROGRAM
Thus the program to implement the dining Philosopher was executed and verified.
EX.NO: 5A DEADLOCK AVOIDANCE
DATE:
AIM:
ALGORITHM:
#include <stdio.h>
void main() {
int pno, rno, i, j, prc, count, total;
count = 0;
printf("\n Enter number of processes: ");
scanf("%d", &pno);
printf("\n Enter number of resources: ");
scanf("%d", &rno);
int flag[pno + 1], tres[rno + 1], max[pno + 1][rno + 1], allocated[pno + 1][rno + 1], need[pno +
1][rno + 1], avail[rno + 1], work[rno + 1];
for (i = 1; i <= pno; i++) {
flag[i] = 0;
}
do {
for (i = 1; i <= pno; i++) {
for (j = 1; j <= rno; j++) {
need[i][j] = max[i][j] - allocated[i][j];
}
}
prc = 0;
for (i = 1; i <= pno; i++) {
if (flag[i] == 0) {
prc = i;
for (j = 1; j <= rno; j++) {
if (work[j] < need[i][j]) {
prc = 0;
break;
}
}
}
if (prc != 0) break;
}
if (prc != 0) {
printf("\n Process %d completed", prc);
count++;
printf("\n Available matrix:");
for (j = 1; j <= rno; j++) {
work[j] += allocated[prc][j];
allocated[prc][j] = 0;
max[prc][j] = 0;
flag[prc] = 1;
printf(" %d", work[j]);
}
}
} while (count != pno && prc != 0);
if (count == pno)
printf("\nThe system is in a safe state!!\n");
else
printf("\nThe system is in an unsafe state!!\n");
}
OUTPUT:
0 1 0| 7 5 3| 7 4 3
3 0 2| 3 2 2| 0 2 0
3 0 2| 9 0 2| 6 0 0
2 1 1| 2 2 2| 0 1 1
0 0 2| 4 3 3| 4 3 1
Process 2 completed
Available matrix: 5 3 2 Allocated matrix
Maxneed
0 1 0| 7 5 3| 7 4 3
0 0 0| 0 0 0| 0 0 0
3 0 2| 9 0 2| 6 0 0
2 1 1| 2 2 2| 0 1 1
0 0 2| 4 3 3| 4 3 1
Process 4 completed
Available matrix: 7 4 3 Allocated matrix
Maxneed
0 1 0| 7 5 3| 7 4 3
0 0 0| 0 0 0| 0 0 0
3 0 2| 9 0 2| 6 0 0
0 0 0| 0 0 0| 0 0 0
0 0 2| 4 3 3| 4 3 1
Process 1 completed
Available matrix: 7 5 3 Allocated matrix Max need
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
3 0 2| 9 0 2| 6 0 0
0 0 0| 0 0 0| 0 00
0 0 2| 4 3 3| 4 31
Process 3 completed
Available matrix: 10 5 5 Allocated matrix Max need
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 2| 4 3 3| 4 3 1
Process 5 completed
Available matrix: 10 57
The system is in a safe state!!
RESULT:
Thus the program to implement the deadlock avoidance was executed and verified.
EX.NO:5B DEADLOCK DETECTION ALGORITHM
DATE:
AIM:
To Simulate Algorithm for Deadlock detection.
ALGORITHM:
#include <stdio.h>
#include <conio.h>
int max[100][100];
int alloc[100][100];
int need[100][100];
int avail[100];
int n, r;
void input();
void show();
void cal();
int main() {
printf("********** Deadlock Detection Algo ************\n");
input();
show();
cal();
getch();
return 0;
}
void input() {
int i, j;
printf("Enter the number of Processes: ");
scanf("%d", &n);
printf("Enter the number of resource instances: ");
scanf("%d", &r);
printf("Enter the Max Matrix:\n");
for (i = 0; i < n; i++) {
for (j = 0; j < r; j++) {
scanf("%d", &max[i][j]);
}
}
printf("Enter the Allocation Matrix:\n");
for (i = 0; i < n; i++) {
for (j = 0; j < r; j++) {
scanf("%d", &alloc[i][j]);
}
}
printf("Enter the available Resources:\n");
for (j = 0; j < r; j++) {
scanf("%d", &avail[j]);
}
}
void show() {
int i, j;
printf("Process\t Allocation\t Max\t Available\n");
for (i = 0; i < n; i++) {
printf("P%d\t ", i + 1);
for (j = 0; j < r; j++) {
printf("%d ", alloc[i][j]);
}
printf("\t");
for (j = 0; j < r; j++) {
printf("%d ", max[i][j]);
}
printf("\t");
if (i == 0) {
for (j = 0; j < r; j++) printf("%d ", avail[j]);
}
printf("\n");
}
}
void cal() {
int finish[100], temp, need[100][100], flag = 1, k, c1 = 0;
int dead[100], safe[100];
int i, j;
j = 0;
flag = 0;
for (i = 0; i < n; i++) {
if (finish[i] == 0) {
dead[j] = i;
j++;
flag = 1;
}
}
if (flag == 1) {
printf("\n\nSystem is in Deadlock and the Deadlock processes are: \n");
for (i = 0; i < j; i++) {
printf("P%d\t", dead[i]);
}
} else {
printf("\n\nThe system is not in a deadlock state.\n");
}
getch();
}
OUTPUT:
AIM:
To write a C program to implement paging concept for memory management.
ALGORITHM:
#include <stdio.h>
#include <conio.h>
int main() {
int ms, ps, nop, np, rempages, i, j, x, y, pa, offset;
int s[10], fno[10][20];
clrscr();
printf("\nEnter the memory size -- ");
scanf("%d", &ms);
printf("\nEnter the page size -- ");
scanf("%d", &ps);
nop = ms / ps;
printf("\nThe number of pages available in memory are -- %d ", nop);
printf("\nEnter number of processes -- ");
scanf("%d", &np);
rempages = nop;
for (i = 1; i <= np; i++) {
printf("\nEnter the number of pages required for p[%d]-- ", i);
scanf("%d", &s[i]);
rempages -= s[i];
printf("\nEnter page table for p[%d] --- ", i);
for (j = 0; j < s[i]; j++) {
scanf("%d", &fno[i][j]);
}
}
getch();
return 0;
}
OUTPUT: