OS Lab Manual
OS Lab Manual
To impart high quality education in Engineering, Technology and Management with a difference,
enabling students to excel in their career by
1. Attracting quality Students and preparing them with a strong foundation in fundamentals so as
to achieve distinctions in various walks of life leading to outstanding contributions.
2. Imparting value based, need based, and choice based and skill based professional education to
the aspiring youth and carving them into disciplined, World class Professionals with social
responsibility.
3. Promoting excellence in Teaching, Research and Consultancy that galvanizes academic
consciousness among Faculty and Students.
4. Exposing Students to emerging frontiers of knowledge in various domains and make them
suitable for Industry, Entrepreneurship, Higher studies, and Research & Development.
5. Providing freedom of action and choice for all the Stake holders with better visibility.
• PSO2 – Applied Engineering Skills: Enable creative thinking, Ability to apply standard
practices and strategies, technical skills in software design, development, integration of systems
and management for improving the security, reliability and survivability of the infrastructure.
• PSO3 – General Expertise and Higher Learning: Ability to exchange knowledge effectively
demonstrate the ability of team work, documentation skills, professional ethics, entrepreneurial
skills and continuing higher education in the field of Information technology.
a. Laboratory observation notes with all the details (Problem statement, Aim,
Algorithm,Procedure, Program, Expected Output, etc.,) filled in for the lab session.
b. Laboratory Record updated up to the last session experiments.
c. Formal dress code and Identity card.
4. Sign in the laboratory login register, write the TIME-IN, and occupy the computer system
allotted to you by the faculty.
5. Execute your task in the laboratory, and record the results / output in the lab observation
note book, and get certified by the concerned faculty.
6. All the students should be polite and cooperative with the laboratory staff, must maintain the
discipline and decency in the laboratory.
7. Computer labs are established with sophisticated and highend branded systems, which
should be utilized properly.
8. Students / Faculty must keep their mobile phones in SWITCHED OFF mode during the lab
sessions. Misuse of the equipment, misbehaviors with the staff and systems etc., will attract
severe punishment.
9. Students must take the permission of the faculty in case of any urgency to go out. If anybody
found loitering outside the lab / class without permission during working hours will be treated
seriously and punished appropriately.
10. Students should SHUT DOWN the computer system before he/she leaves the lab after
completing the task (experiment) in all aspects. He/she must ensure the system / seat is kept
properly.
All students must observe the dress code while in the laboratory
Footwear is NOT allowed
Foods, drinks and smoking are NOT allowed
All bags must be left at the indicated place
The lab timetable must be strictly followed
Be PUNCTUAL for your laboratory session
All programs must be completed within the given time
Noise must be kept to a minimum
Workspace must be kept clean and tidy at all time
All students are liable for any damage to system due to their own negligence
Students are strictly PROHIBITED from taking out any items from the laboratory
Report immediately to the lab programmer if any damages to equipment
Understanding
Able to analyze the given Able to analyze the
of problem and No program
problem and efficiently problem and moderate
a. approach to write-up.
implement using suitable understanding of test
solve. (1-0)
language.(5-4) cases. (3-2)
( 5 Marks)
Execution and Program is executed for
Program is executed for No Execution.
b. Testing varied and invalid inputs
some inputs. (3-2) (1-0)
(5 Marks) with valid results.(5-4)
No Proper
Results and Program and results Program and results
results and poor
c. Documentation obtained is well obtained is acceptably
documentation.
(5 Marks) documented(5-4) documented(3-2)
(1-0)
LAB Internal Assessment rubrics (Max: 10 marks)
Executed successfully
Execution Obtained Partially No Execution.
b. for all the input set
(4 Marks) correct results. (3-2) (1-0)
given (4)
Able to answer all the Able to answer few Not answered
c. Viva (2 Marks)
questions correctly (2) questions (1) any. (0)
Linux CASE STUDY: Perform a case study by installing and exploring various types of
operating systems on a physical or logical (virtual) machine. (Linux Installation).
Instructions to Install Ubuntu 12.04 (LTS) along with Windows
Back Up Your Existing Data
This is highly recommended that you should take backup of your entire data before start
with the installation process.
In a few minutes installation wizard will be started. Select your language and click the
"Install Ubuntu" button to continue...
Optionally, you can choose to download updates while installing and/or install third party
software, such as MP3 support. Be aware, though, that if you select those options, the entire
installation process will be longer!
Since we are going to create partitions manually, select Something else, then click Continue. Keep in
mind that even if you do not want to create partitions manually, it is better to select the same option as
indicated here. This would insure that the installer will not overwrite yourWindows, which will
destroy your data. The assumption here is that sdb will be used just for Ubuntu 12.04, and that there
are no valuable data on it.
Where are you? Select your location and Click the "Continue" button.
Keyboard layout
Select your keyboard layout and UK (English) and Click on “Continue” button.
Also at this step, there's an option called "Log in automatically." If you check it, you willautomatically
be logged in to the Ubuntu desktop without giving the password.
Option "Encrypt my home folder," will encrypt your home folder. Click on the "Continue"button to
continue...
10
Now Ubuntu 12.04 LTS (Precise Pangolin) operating system will be installed.
It will take approximately 10-12 minutes (depending on computer's speed), a pop-up window will
appear, notifying you that the installation is complete, and you'll need to restart thecomputer in
order to use the newly installed Ubuntu operating system. Click the "Restart Now" button.
11
Please remove the CD and press the "Enter" key to reboot. The computer will be restarted. In a few
seconds, you should see Windows 7′s boot menu with two entires listed – Windows 7 andUbuntu
12.04 (LTS).
Then you may choose to boot into Windows 7 or Ubuntu 12.04 using the UP/Down arrow key.
Please select Ubuntu 12.04 (LTS) and press Enter to boot the machine in Ubuntu 12.04
Linux.
12
Here you can see the users on the machine, Click on the user name and enter the password and press
Enter key to login.
13
Operating System Lab Manual
PROGRAM 1: Develop a c program to implement the Process system calls (fork (), exec(),
wait(), create process, terminate process)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
// Variable to store the process ID.
pid_t child_pid; char ch[3];
// Create a child process using fork().
child_pid = fork();
if (child_pid == -1) {
// Error occurred during fork.
perror("fork");
exit(EXIT_FAILURE);
}
if (child_pid == 0) {
// This code executes in the child process.
printf("Child process (PID: %d) is running.\n", getpid());
// Execute a different program using exec().
//abort(); child terminated abnormally by sending signal number 6 to the parent
// return(-1); child terminates with exit status 255
execl("/bin/date","date", NULL);
exit(0);
}
else {
// This code executes in the parent process.
printf("Parent process (PID: %d) is waiting for the child to terminate.\n", getpid());
// Wait for the child process to terminate using wait().
int status;
wait(&status);
printf("parent resumes\n");
if (WIFEXITED(status)) {
printf("\nChild process (PID: %d) terminated with status %d.\n", child_pid,
WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("\nChild process (PID: %d) terminated due to signal %d.\n", child_pid,
WTERMSIG(status));
} else {
printf("\nChild process (PID: %d) terminated abnormally.\n", child_pid);}
}
return 0;
}
output
Operating System Lab Manual
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc pgm1.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
Parent process (PID: 11284) is waiting for the child to terminate.
Child process (PID: 11285) is running.
parent resumes
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc pgm1.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
Parent process (PID: 11356) is waiting for the child to terminate.
Child process (PID: 11357) is running.
parent resumes
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc pgm1.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
Parent process (PID: 11433) is waiting for the child to terminate.
Child process (PID: 11434) is running.
Tue Oct 10 10:50:07 IST 2023
parent resumes
//FCFS
#include<stdio.h>
int main()
{
int bt[20], wt[20], tat[20], i, n;
float wtavg, tatavg;
output:
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc fcfs.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
P0 24 0 24
P1 3 24 27
P2 3 27 30
Average Waiting Time -- 17.000000
Average Turnaround Time -- 27.000000
//SJF
#include<stdio.h>
int main()
{
int p[20], bt[20], wt[20], tat[20], i, k, n, temp;
float wtavg, tatavg;
printf("\nEnter the number of processes -- ");
scanf("%d", &n);
for(i=0;i<n;i++)
{
p[i]=i;
printf("Enter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(bt[i]>bt[k])
{
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
Operating System Lab Manual
temp=p[i];
p[i]=p[k];
p[k]=temp;
}
wt[0] = wtavg = 0;
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] +bt[i-1];
tat[i] = tat[i-1] +bt[i];
wtavg = wtavg + wt[i];
tatavg = tatavg + tat[i];
}
for(i=0;i<n;i++)
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", p[i], bt[i], wt[i], tat[i]);
printf("\nAverage Waiting Time -- %f", wtavg/n);
printf("\nAverage Turnaround Time -- %f", tatavg/n);
}
output:
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc sjf.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
P2 7 0 7
P1 8 7 15
P0 10 15 25
Average Waiting Time -- 7.333333
Average Turnaround Time -- 15.666667
//Round Robin
#include<stdio.h>
int main()
{
int i,j,n,bu[10],wa[10],tat[10],t,ct[10],max;
float awt=0,att=0,temp=0;
printf("Enter the no of processes -- ");
scanf("%d",&n);
for(i=0;i<n;i++)
Operating System Lab Manual
{
printf("\nEnter Burst Time for process %d -- ", i+1);
scanf("%d",&bu[i]);
ct[i]=bu[i];
}
printf("\nEnter the size of time slice -- ");
scanf("%d",&t);
max=bu[0];
for(i=1;i<n;i++)
if(max<bu[i])
max=bu[i];
for(j=0;j<(max/t)+1;j++)
for(i=0;i<n;i++)
if(bu[i]!=0)
if(bu[i]<=t)
{
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
}
else
{
bu[i]=bu[i]-t;
temp=temp+t;
}
for(i=0;i<n;i++)
{
wa[i]=tat[i]-ct[i];
att+=tat[i];
awt+=wa[i];
}
output:
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc rr.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
Enter the no of processes -- 3
//Priority
#include<stdio.h>
int main()
{
int p[20],bt[20],pri[20], wt[20],tat[20],i, k, n, temp;
float wtavg, tatavg;
printf("Enter the number of processes --- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
p[i] = i;
printf("Enter only positive numbers\n");
printf("Enter the Burst Time & Priority of Process %d --- ",i);
scanf("%d %d",&bt[i], &pri[i]);
}
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(pri[i] > pri[k])
{
temp=p[i];
p[i]=p[k];
p[k]=temp;
temp=bt[i];
Operating System Lab Manual
bt[i]=bt[k];
bt[k]=temp;
temp=pri[i];
pri[i]=pri[k];
pri[k]=temp;
}
wtavg = wt[0] = 0;
tatavg = tat[0] = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] + bt[i-1];
tat[i] = tat[i-1] + bt[i];
wtavg = wtavg + wt[i];
tatavg = tatavg + tat[i];
}
output:
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
Enter the number of processes --- 3
Enter the Burst Time & Priority of Process 0 --- 10 3
Enter the Burst Time & Priority of Process 1 --- 8 1
Enter the Burst Time & Priority of Process 2 --- 7 2
//producer consumer
#include<stdio.h>
#include <stdlib.h>
int mutex = 1;
int full = 0;
int empty = 3, x = 0;
void producer()
{
Operating System Lab Manual
--mutex;
++full;
--empty;
x++;
printf("\nProducer produces item %d",x);
++mutex;
}
void consumer()
{
--mutex;
--full;
++empty;
printf("\nConsumer consumes item %d",x);
x--;
++mutex;
}
int main()
{
int n, i;
printf("\n1. Press 1 for Producer"
"\n2. Press 2 for Consumer"
"\n3. Press 3 for Exit");
else
{
printf("Buffer is full!");
}
break;
case 2:
if ((mutex == 1)&& (full != 0))
{
consumer();
}
else
{
printf("Buffer is empty!");
Operating System Lab Manual
}
break;
case 3:
exit(0);
break;
}
}
}
output:
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
/* Reader Process */
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#define MAX_BUF 1024
int main()
{
int fd;
/* A temp FIFO file is not created in reader */
char *myfifo = "/tmp/guest-uivabk/Desktop/tmp";
char buf[MAX_BUF];
/* open, read, and display the message from the FIFO */
fd = open(myfifo, O_RDONLY);
read(fd, buf, MAX_BUF);
printf("Reader process has read : %s\n", buf);
close(fd);
return 0;
}
******output **********
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc writer.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
Run Reader process to read the FIFO File
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc reader.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
Reader process has read : Hello RNSIT
#include<stdio.h>
struct file
{
Operating System Lab Manual
int all[10];
int max[10];
int need[10];
int flag;
};
void main()
{
struct file f[10]; int fl;
int i, j, k, p, b, n, r, g, cnt=0, id, newr;
int avail[10],seq[10];
while(cnt!=n)
{
g=0;
for(j=0;j<n;j++)
{
if(f[j].flag==0)
{
b=0;
for(p=0;p<r;p++)
{
if(avail[p]>=f[j].need[p])
b=b+1;
Operating System Lab Manual
else
b=b-1;
}
if(b==r)
{
printf("\nP%d is visited",j);
seq[fl++]=j;
f[j].flag=1;
for(k=0;k<r;k++)
avail[k]=avail[k]+f[j].all[k];
cnt=cnt+1;
printf("(");
for(k=0;k<r;k++)
printf("%3d",avail[k]);
printf(")");
g=1;
}
}
}
if(g==0)
{
printf("\n REQUEST NOT GRANTED -- DEADLOCK OCCURRED");
printf("\n SYSTEM IS IN UNSAFE STATE");
goto y;
}
}
printf("\nSYSTEM IS IN SAFE STATE");
printf("\nThe Safe Sequence is -- (");
for(i=0;i<fl;i++)
printf("P%d ",seq[i]);
printf(")");
y: printf("\nProcess\t\tAllocation\t\tMax\t\t\tNeed\n");
for(i=0;i<n;i++)
{
printf("P%d\t",i);
for(j=0;j<r;j++)
printf("%6d",f[i].all[j]);
for(j=0;j<r;j++)
printf("%6d",f[i].max[j]);
for(j=0;j<r;j++)
printf("%6d",f[i].need[j]); printf("\n");
}
*****output*****
guest-yk70yi@student-OptiPlex-3040:~$ cc bankers.c
guest-yk70yi@student-OptiPlex-3040:~$ ./a.out
Enter number of processes -- 5
Enter number of resources -- 3
Enter details for P0
Enter allocation -- 010
Enter Max -- 753
Operating System Lab Manual
Enter details for P1
Enter allocation -- 200
Enter Max -- 322
Enter details for P2
Enter allocation -- 302
Enter Max -- 902
Enter details for P3
Enter allocation -- 211
Enter Max -- 222
Enter details for P4
Enter allocation -- 002
Enter Max -- 433
P1 is visited( 5 3 2)
P3 is visited( 7 4 3)
P4 is visited( 7 4 5)
P0 is visited( 7 5 5)
P2 is visited( 10 5 7)
SYSTEM IS IN SAFE STATE
The Safe Sequence is -- (P1 P3 P4 P0 P2 )
Process Allocation Max Need
P0 0 1 0 7 5 3 7 4 3
P1 2 0 0 3 2 2 1 2 2
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1
//**********FIRST FIT**********
#include<stdio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
printf("\n\tMemory Management Scheme - First Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
Operating System Lab Manual
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i]; if(temp>=0)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp; bf[ff[i]]=1;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
//getch();
}
*********OUTPUT************
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
//****************BEST FIT*****************************
#include<stdio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
printf("\n\tMemory Management Scheme - Best Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i]; if(temp>=0)
if(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
}
Operating System Lab Manual
}
frag[i]=lowest; bf[ff[i]]=1; lowest=10000;
}
printf("\nFile No\tFile Size \tBlock No\tBlock Size\tFragment");
for(i=1;i<=nf && ff[i]!=0;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
//getch();
}
OUTPUT:
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc worstfit.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
// WORST FIT
#include<stdio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
static int bf[max],ff[max];
printf("\n\tMemory Management Scheme - Worst Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
Operating System Lab Manual
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1) //if bf[j] is not allocated
{
temp=b[j]-f[i]; if(temp>=0)
if(highest<temp)
{
ff[i]=j; highest=temp;
}
}
}
frag[i]=highest;
bf[ff[i]]=1;
highest=0;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
OUTPUT:
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc worstfit.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
//FIFO
#include<stdio.h>
void main()
{
int i, j, k, f, pf=0, count=0, rs[25], m[10], n;
printf("\n Enter the length of reference string -- ");
scanf("%d",&n);
printf("\n Enter the reference string -- ");
for(i=0;i<n;i++)
scanf("%d",&rs[i]);
printf("\n Enter no. of frames -- ");
scanf("%d",&f);
for(i=0;i<f;i++)
m[i]=-1;
for(j=0;j<f;j++)
printf("\t%d",m[j]);
if(k==f)
printf("\tPF No. %d",pf);
printf("\n");
if(count==f)
count=0;
}
printf("\n The number of Page Faults using FIFO are %d",pf);
}
OUTPUT:
guest-yk70yi@student-OptiPlex-3040:~$ ./a.out
//LRU
#include<stdio.h>
int main()
{
int i, j , k, min, rs[25], m[10], count[10], flag[25], n, f, pf=0, next=1;
m[min]=rs[i];
count[min]=next;
next++;
}
pf++;
}
for(j=0;j<f;j++)
printf("%d\t", m[j]);
if(flag[i]==0)
printf("PF No. -- %d" , pf);
printf("\n");
}
printf("\nThe number of page faults using LRU are %d",pf);
}
OUTPUT:
guest-yk70yi@student-OptiPlex-3040:~$ ./a.out
Enter the length of reference string -- 20
Enter the reference string -- 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
Enter the number of frames -- 3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_FILES 10
#define MAX_FILENAME_LENGTH 10
char directoryName[MAX_FILENAME_LENGTH];
char filenames[MAX_FILES][MAX_FILENAME_LENGTH];
int fileCount = 0;
void createFile() {
if (fileCount < MAX_FILES) {
char filename[MAX_FILENAME_LENGTH];
printf("Enter the name of the file: ");
scanf("%s", filename);
strcpy(filenames[fileCount], filename);
fileCount++;
printf("File %s created.\n", filename);
} else {
printf("Directory is full, cannot create more files.\n");
}
}
void deleteFile() {
if (fileCount == 0) {
printf("Directory is empty, nothing to delete.\n");
return;
}
char filename[MAX_FILENAME_LENGTH];
printf("Enter the name of the file to delete: ");
scanf("%s", filename);
int found = 0;
for (int i = 0; i < fileCount; i++) {
if (strcmp(filename, filenames[i]) == 0) {
found = 1;
printf("File %s is deleted.\n", filename);
strcpy(filenames[i], filenames[fileCount - 1]);
fileCount--;
Operating System Lab Manual
break;
}
}
if (!found) {
printf("File %s not found.\n", filename);
}
}
void displayFiles() {
if (fileCount == 0) {
printf("Directory is empty.\n");
} else {
printf("Files in the directory %s:\n", directoryName);
for (int i = 0; i < fileCount; i++) {
printf("\t%s\n", filenames[i]);
}
}
}
int main() {
printf("Enter the name of the directory: ");
scanf("%s", directoryName);
while (1) {
printf("\n1. Create File\t2. Delete File\t3. Search File\n4. Display Files\t5. Exit\nEnter your choice:");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
createFile();
break;
case 2:
deleteFile();
break;
case 3:
printf("Enter the name of the file: ");
char searchFilename[MAX_FILENAME_LENGTH];
scanf("%s", searchFilename);
int found = 0;
for (int i = 0; i < fileCount; i++) {
if (strcmp(searchFilename, filenames[i]) == 0) {
found = 1;
printf("File %s is found.\n", searchFilename);
break;
}
}
if (!found) {
printf("File %s not found.\n", searchFilename);
}
break;
case 4:
displayFiles();
break;
case 5:
exit(0);
default:
Operating System Lab Manual
printf("Invalid choice, please try again.\n");
}
}
return 0;
}
OUTPUT:
guest-yk70yi@student-OptiPlex-3040:~$ ./a.out
Enter the name of the directory: rns
#include <stdio.h>
#include <stdlib.h>
int main(){
int f[50], p, i, st, len, j, c, k, a, fn=0;
if (f[st] == 0)
{
for (j = st; j < (st + k); j++){
if (f[j] == 0)
{
f[j] = fn;
printf("%d-------->%d\n", j, f[j]);
}
else{
printf("%d Block is already allocated \n", j);
k++;
}
}
}
else
printf("%d starting block is already allocated \n", st);
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if (c == 1)
goto x;
else
Operating System Lab Manual
exit(0);
return 0;
}
OUTPUT:
*****only allocation is simulated*********
guest-uivabk@student-OptiPlex-3040:~/Desktop$ cc pgm9.c
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
Enter index starting block and length: 1 3
1-------->1
2-------->1
3-------->1
Do you want to enter more file(Yes - 1/No - 0)1
Enter index starting block and length: 5 3
5-------->2
6-------->2
7-------->2
Do you want to enter more file(Yes - 1/No - 0)1
Enter index starting block and length: 4 5
4-------->3
5 Block is already allocated
6 Block is already allocated
7 Block is already allocated
8-------->3
9-------->3
10-------->3
11-------->3
Do you want to enter more file(Yes - 1/No - 0)0
#include<stdio.h>
int main()
{
int t[20], d[20], h, i, j, n, temp, k, atr[20], tot, p, sum=0;
}
}
}
for(i=0;i<n+2;i++)
if(t[i]==h)
{
j=i;
k=i;
p=0;
}
while(t[j]!=0)
{
atr[p]=t[j];
j--;
p++;
}
atr[p]=t[j];
for(p=k+1;p<n+2;p++,k++)
atr[p]=t[k+1];
printf("seek sequence is:");
for(j=0;j<n+1;j++)
{
if(atr[j]>atr[j+1])
d[j]=atr[j]-atr[j+1];
else
d[j]=atr[j+1]-atr[j];
sum+=d[j];
printf("\n%d", atr[j]);
}
printf("\nTotal head movements:%d",sum);
}
OUTPUT:
guest-uivabk@student-OptiPlex-3040:~/Desktop$ ./a.out
enter the no of tracks to be traveresed8
enter the position of head50
enter the tracks176
79
34
60
92
11
41
114
seek sequence is:
50
41
Operating System Lab Manual
34
11
0
60
79
92
114
Total head movements:226
Operating System Lab Manual