INDEX
Sno. Program Date Page no.
1 To explore linux commands. 11-01-2022 3
2 To explore more basic commands of linux 18-01-2022 8
3 To explore some more basic commands and Vi 25-01-2022 13
editor commands in linux.
4 1. To explore chmod command and about pipes. 01-02-2022 17
2. Write a program in to implement FCFS CPU
Scheduling algorithm
5 Write a program to implement Shortest Job First 15-02-2022 24
algorithm
6 Write a program to implement Priority Scheduling 22-02-2022 28
algorithm
7 Write a program to implement Robin Round 08-03-2022 31
Scheduling algorithm
8 1. Write a Script to swap two numbers. 15-03-2022
2. Write a Script to delete a file whose name is
input by the user.
3. Write a Script to calculate area of a rectangle
and a circle.
9 1. Write a Script to check whether the number is 22-03-2022
positive,negative or zero
2. Write a Script to print whether the number is
odd or even
3. Write a Script to check whether user is a valid
user or not.
10 1. Write a Script to print Fibonacci series. 29-03-2022
2. Write a Script to reverse a number.
3. Write a Script to find a factorial of a number.
11 05-04-2022
Algorithm
2
12 1. Write a program to implement FCFS Disk 12-04-2022
scheduling algorithm
2. Write a program to implement SSTF Disk
scheduling algorithm.
3
EXPERIMENT-1
DATE- 11-01-2022
OBJECTIVE- To explore linux commands
SOFTWARE USED- CYGWIN64 TERMINAL
THEORY-
1. ls this command is used to list all the files in the current directory
2. ls - - help this command is used to list the commands in help file
4
5
3. man ls this command is used to list the user manual
4. clear this command clears the screen
5. alias- this command changes the name of the command according to you
6. unalias- this command is used to remove the entries from the current user's list of aliases
7. cat this command is used to concatenate files, create single/multiple files, view contents of the
file
6
8. cat -n this command is used to number the output lines
9. who- this command is used to get the information about the currently logged in user to the
system
10. whoami this command is used to get information about my system
11. echo -this command is used to display line of text/string that are passed as an argument
12. uname- this command is used to display information about OS like its machine name,kernel,etc.
13. uname -v this command tells about OS version
14. history- this commands lists all the commands which we have entered before
15. !(no. of the command in history)- this executes the command at the specific number in the
history
16. pwd- this command prints the working directory
7
17. cd- this command changes the directory
18. mkdir- this command creates a new directory
19. rmdir- this command deletes an empty directory
20. cd .. this command goes to the previous directory
21. cd . this command keeps you on the current directory
8
EXPERIMENT-2
DATE- 18-01-2022
OBJECTIVES- To explore more basic commands of linux
SOFTWARE USED- CYGWIN64 TERMINAL
THEORY-
1. cp this command is used to copy a file, create a duplicate copy of a file.
Creating a duplicate file
Copying a directory with its files
Copying multiple directories
Interactive cp
2. mv this command is used to rename a file, move files or directories
from one place to another
9
Rename a file
Moving a file to the directory with same name
Moving a file to the directory with a different name
Moving multiple files to a directory
10
Moving a directory
Interactive mv
3. rm this command is used to remove file
11
4. cmp this command is used to compare two files byte by byte
When file is identical
When file is not identical
Displaying first difference in file
Supressing
5. wc this command is used for printing newline, returns number of
lines/characters/words in a file
Printing new line
Counting number of bytes
12
Printing number of lines
Printing number of characters
Printing number of words
13
EXPERIMENT-3
DATE- 25-01-2022
OBJECTIVE- To explore some more basic commands and Vi editor commands in
linux.
SOFTWARE- CYGWIN64 TERMINAL
THEORY-
1. comm this command is used to display the common words in the two
sorted files.
Displaying common words between two files
Dropping 1st and 2nd column
Dropping 3rd column
14
2. sort this command is used to sort file
Sorting file in alphabetical order
Sorting numbers in file from lowest to highest
Sorting file in reverse order
VI EDITOR
VI editor is a text editor in linux family.
It has three modes
15
i. Command mode-
In command mode, we can move through a file, delete, copy a piece
of text in the file. Editor always opens in command mode but if we
want to enter into the command mode from another mode we can
press [esc].
ii. Insert mode-
In insert mode, we can insert text into the file.
insert mode by pressing [esc].
iii. Escape mode-
In escape mode, we can save files and execute commands.
It can be invoked by typing a colon [:], when VI is in Command Mode.
The cursor will jump to the last line of the screen and vi will wait for a
command.
Some commands
Inserting text in file Editor is in insert mode
[esc]- Editor returns to command mode
dd deletes a line
dw- deletes a word
16
3dw- deletes 3 words
x deletes character at the cursor
r replaces character a the cursor
Saving a file [Escape mode]
:w
17
EXPERIMENT-4
DATE- 01-02-2022
OBJECTIVE- 1. To explore chmod command and about pipes.
2. Write a program in to implement FCFS CPU Scheduling algorithm
SOFTWARE USED- CYGWIN64 TERMINAL
THEORY-
There are three types of permissions associated with a file:
i. read- It allows the user to view the contents of the file.
ii. write- It allows the user to write/add the contents in the file.
iii. execute- It enables the user to run a file, such as shell script or
a binary program file.
There are different classes of users who have permission access rights of
the file.
i. user (u)- The file owner
ii. group (g)- The group members
iii. other (o)- other users
chmod- This command allows the user to change the permissions of a file. It
can be done using two ways-
1. Symbolic method-
The permissions can be changed explicitly using letters r,w,x for different
users u,g,o. Permissions can be changed through the following
operators:
(+) - Adds the specified permission
18
(-) Removes the specified permission
(=) Changes the current permission to the specified permission
2. Numeric mode
The permissions can be set or changed using numbers. Through this
mode we can set or change the permission for all classes together.
Values are assigned to the classes in the ugo order.
Numeric values: read-4, write-2, execute-1
To assign all three modes to a class: read + write + execute = 4+2+1 = 7
To assign read and write modes to a class: read + write = 4+2+0 = 6
To assign read and execute modes to a class: read + execute = 4+1 = 5
To assign write and execute modes to a class: write + execute = 2+1 = 3
19
ping- It lets you verify that you have network connectivity with another
network device. It is commonly used to help troubleshoot networking
issues.
20
ps It lists running processes.
tty It stands for TeleTYpewriter. It is used to print the filename of the
terminal connected to standard input.
kill It is used to terminate a process. A root user can kill system level
process and the process started by some other user.
Pipes- It is a form of redirection. It connects the output of one program to
the input of another program without any temporary file.
21
Write a program in C to implement FCFS CPU Scheduling algorithm
#include<stdio.h>
#include<string.h>
int main()
{
char pn[10][10],t[10];
int arr[10],bur[10],star[10],finish[10],tat[10],wt[10],i,j,n,temp;
int totwt=0,tottat=0;
printf("Enter the number of processes:");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("Enter the ProcessName, Arrival Time& Burst Time:");
scanf("%s%d%d",&pn[i],&arr[i],&bur[i]);
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
22
arr[i]=arr[j];
arr[j]=temp;
temp=bur[i];
bur[i]=bur[j];
bur[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
}
}
}
for(i=0; i<n; i++)
{
if(i==0)
star[i]=arr[i];
else
star[i]=finish[i-1];
wt[i]=star[i]-arr[i];
finish[i]=star[i]+bur[i];
tat[i]=finish[i]-arr[i];
}
printf("\nPName Arrtime Burtime WaitTime Start TAT Finish");
for(i=0; i<n; i++)
{
23
printf("\n%s\t%3d\t%3d\t%3d\t%3d\t%6d\t%6d",pn[i],arr[i],bur[i],wt[i],star[i],
tat[i],finish[i]);
totwt+=wt[i];
tottat+=tat[i];
}
printf("\nAverage Waiting time:%f",(float)totwt/n);
printf("\nAverage Turn Around Time:%f",(float)tottat/n);
return 0;
}
24
EXPERIMENT-5
DATE- 15-02-2022
OBJECTIVE- Write a program to implement Shortest Job First algorithm
CODE-
#include <iostream>
using namespace std;
int mat[10][6];
void swap(int* a, int* b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void arrangeArrival(int num, int mat[][6])
{
for (int i = 0; i < num; i++) {
for (int j = 0; j < num - i - 1; j++) {
if (mat[j][1] > mat[j + 1][1]) {
for (int k = 0; k < 5; k++) {
swap(mat[j][k], mat[j + 1][k]);
}
}
}
}
25
}
void completionTime(int num, int mat[][6])
{
int temp, val;
mat[0][3] = mat[0][1] + mat[0][2];
mat[0][5] = mat[0][3] - mat[0][1];
mat[0][4] = mat[0][5] - mat[0][2];
for (int i = 1; i < num; i++) {
temp = mat[i - 1][3];
int low = mat[i][2];
for (int j = i; j < num; j++) {
if (temp >= mat[j][1] && low >= mat[j][2]) {
low = mat[j][2];
val = j;
}
}
mat[val][3] = temp + mat[val][2];
mat[val][5] = mat[val][3] - mat[val][1];
mat[val][4] = mat[val][5] - mat[val][2];
for (int k = 0; k < 6; k++) {
swap(mat[val][k], mat[i][k]);
}
}
}
26
int main()
{
int num, temp;
cout << "Enter number of Process: ";
cin >> num;
cout << "...Enter the process no.\n";
for (int i = 0; i < num; i++) {
cout << "...Process " << i + 1 << "...\n";
cout << "Enter Process Id: ";
cin >> mat[i][0];
cout << "Enter Arrival Time: ";
cin >> mat[i][1];
cout << "Enter Burst Time: ";
cin >> mat[i][2];
}
cout << "Process ID\tArrival Time\tBurst Time\n";
for (int i = 0; i < num; i++) {
cout << mat[i][0] << "\t\t" << mat[i][1] << "\t\t"
<< mat[i][2] << "\n";
}
27
arrangeArrival(num, mat);
completionTime(num, mat);
cout << "Final Result...\n";
cout << "Process ID\tArrival Time\tBurst Time\tWaiting "
"Time\tTurnaround Time\n";
for (int i = 0; i < num; i++) {
cout << mat[i][0] << "\t\t" << mat[i][1] << "\t\t"
<< mat[i][2] << "\t\t" << mat[i][4] << "\t\t"
<< mat[i][5] << "\n"; }
}
Output:
28
EXPERIMENT-6
DATE- 22-02-2022
OBJECTIVE- Write a program to implement Priority Scheduling algorithm
CODE-
#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
printf("Enter Total Number of Process:");
scanf("%d",&n);
printf("\nEnter Burst Time and Priority\n");
for(i=0;i<n;i++)
{
printf("\nP[%d]\n",i+1);
printf("Burst Time:");
scanf("%d",&bt[i]);
printf("Priority:");
scanf("%d",&pr[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
29
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
30
avg_wt=total/n; //average waiting time
total=0;
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("\nP[%d]\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=total/n; //average turnaround time
printf("\n\nAverage Waiting Time=%d",avg_wt);
printf("\nAverage Turnaround Time=%d\n",avg_tat);
return 0;
}
Output:
31
EXPERIMENT-7
DATE- 08-03-2022
OBJECTIVE- Write a program to implement Robin Round Scheduling algorithm
CODE-
#include<stdio.h>
#include<conio.h>
int main()
{
int i, NOP, sum=0,count=0, y, quant, wt=0, tat=0, at[10], bt[10], temp[10];
float avg_wt, avg_tat;
printf(" Total number of process in the system: ");
scanf("%d", &NOP);
y = NOP;
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");
scanf("%d", &at[i]);
printf(" \nBurst time is: \t");
scanf("%d", &bt[i]);
temp[i] = bt[i];
}
printf("Enter the Time Quantum for the process: \t");
scanf("%d", &quant);
printf("\n Process No \t\t Burst Time \t\t TAT \t\t Waiting Time ");
for(sum=0, i = 0; y!=0; )
32
{
if(temp[i] <= quant && temp[i] > 0)
{
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--;
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)
{
33
i++;
}
else
{
i=0;
}
}
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:
34
EXPERIMENT-8
DATE 15-03-2022
OBJECTIVE-
1. Write a Script to swap two numbers.
CODE-
Output:
2. Write a Script to delete a file whose name is input by the user.
CODE-
Output:
35
3. Write a Script to calculate area of a rectangle.
CODE-
Output:
36
EXPERIMENT-9
DATE 22-03-2022
OBJECTIVE-
1. Write a Script to check whether the number is positive,negative or zero.
CODE-
Output:
37
2. Write a Script to print whether the number is odd or even.
CODE-
Output:
38
3. Write a Script to check whether user is a valid user or not.
CODE-
Output:
39
EXPERIMENT-10
DATE 29-03-2022
OBJECTIVE-
1. Write a Script to print Fibonacci series.
CODE-
echo "Enter the value of n"
read n
a=0
b=1
count=2
echo "Fibonacci series:"
echo $a
echo $b
while [ $count -le $n ]
do
fib=`expr $a + $b`
a=$b
b=$fib
echo $fib
count=`expr $count + 1`
done
Output:
2. Write a Script to reverse a number.
CODE-
echo enter n
read n
40
num=0
while [ $n -gt 0 ]
do
num=$(expr $num \* 10)
k=$(expr $n % 10)
num=$(expr $num + $k)
n=$(expr $n / 10)
done
echo number is $num
Output:
3. Write a Script to find a factorial of a number.
CODE-
echo -n "Enter a number: "
read number
factorial=1
for(( i=1; i<=number; i++ ))
do
factorial=$[ $factorial * $i ]
done
echo "The factorial of $number is $factorial"
Output:
41
EXPERIMENT-11
DATE- 05-04-2022
OBJECTIVE-
CODE-
#include <stdio.h>
int main()
{
int np, nr, i, j, k;
np = 5; // Number of processes
nr = 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 max[5][3] = { { 7, 5, 3 }, // P0 // MAX Matrix
{ 3, 2, 2 }, // P1
{ 9, 0, 2 }, // P2
{ 2, 2, 2 }, // P3
{ 4, 3, 3 } }; // P4
int avail[3] = { 3, 3, 2 }; // Available Resources
int f[np], ans[np], ind = 0;
for (k = 0; k < np; k++) {
f[k] = 0;
}
42
int need[np][nr];
for (i = 0; i < np; i++) {
for (j = 0; j < nr; j++)
need[i][j] = max[i][j] - alloc[i][j];
}
int y = 0;
for (k = 0; k < 5; k++) {
for (i = 0; i < np; i++) {
if (f[i] == 0) {
int flag = 0;
for (j = 0; j < nr; j++) {
if (need[i][j] > avail[j]){
flag = 1;
break;
}
}
if (flag == 0) {
ans[ind++] = i;
for (y = 0; y < nr; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}
int flag = 1;
43
for(int i=0;i<np;i++)
{
if(f[i]==0)
{
flag=0;
printf("The following system is not safe");
break;
}
}
if(flag==1)
{
printf("Following is the SAFE Sequence\n");
for (i = 0; i < np - 1; i++)
printf(" P%d ->", ans[i]);
printf(" P%d", ans[np - 1]);
}
return 0;
}
Output:
44
EXPERIMENT-12
DATE- 08-03-2022
OBJECTIVE-
1. Write a program to implement FCFS Disk scheduling algorithm.
CODE-
#include<stdio.h>
#include<stdlib.h>
int main()
{
int req[100],i,n,t=0,initial;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&req[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
for(i=0;i<n;i++)
{
t= t + abs(req[i]-initial);
initial=req[i];
}
printf("Total head moment is %d",t);
return 0;
}
45
Output:
2. Write a program to implement SSTF Disk scheduling algorithm.
CODE-
#include<stdio.h>
#include<stdlib.h>
int main()
{
int req[100],i,n,t=0,initial,count=0;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&req[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
while(count!=n)
{
int min=1000,d,index;
for(i=0;i<n;i++)
46
{
d=abs(req[i]-initial);
if(min>d)
{
min=d;
index=i;
}
}
t=t+min;
initial=req[index];
req[index]=1000;
count++;
}
printf("Total head movement is %d",t);
return 0;
}
Output:
47