Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

SCHOOL OF COMPUTER SCIENCE AND ENGINEERING

BCA
(IInd YEAR -IVSEM)(2022-23)
Code: 21BCA481

OPERATING SYSTEMS LAB MANUAL

SUBMITTED TO:- SUBMITTED BY:-


Mr. Rohit Goyal NAME:-
BRANCH:-
SECTION:-
ADMISSION NO.:-
S.No List of Experiments in OS Date

1. How do you modify the attributes of a file using the command prompt?

2. List the internal and external DOS commands with the help of examples.

Write any five Linux commands with using examples.


3.
4. Write the Linux command “rmdir/s foldername” to delete folder having files
in it.
5. Write a program in Linux that takes two numbers as input and displays their
sum on the screen.
6. Implement file allocation strategies for Sequential storage.

7. Implement linked file allocation strategy.

8. Implement Bankers Algorithm for Dead Lock Prevention.

9. Implement the page replacement algorithms for FIFO.

10 Implement Paging technique for memory management.


EXPERIMENT NO.1:

AIM: To modify attribute of file using command prompt.


You can modify the attributes of a file using the command prompt in Windows by using the attrib
command.
Here are the steps to modify the attributes of a file:
Open the command prompt. You can do this by clicking on the Start menu, typing "cmd" in the search
box, and then clicking on the Command Prompt icon.
1. Navigate to the directory that contains the file whose attributes you want to modify using the
cd command.
2. To modify the attributes of the file, use the attrib command followed by the file name and the
desired attributes.
For example, to set the file to read-only, use the command attrib +r filename.
3. To remove the read-only attribute, use the command attrib -r filename. Here are some of the
most common attributes you can modify:
i) +r: Sets the read-only attribute.
i) -r: Removes the read-only attribute.
iii) +h: Sets the hidden attribute.
iv) -h: Removes the hidden attribute.
v) +s: Sets the system attribute.
vi) -s: Removes the system attribute.
Press Enter to execute the command. The attributes of the file will be modified accordingly.
Note that in order to modify the attributes of a file, you need to have the necessary permissions.
EXPERIMENT NO.2:

AIM: List the internal and external DOS commands with the help of examples.

DOS (Disk Operating System) is a command-line interface used in older Microsoft operating systems,
such as MS-DOS and Windows 95/98. It consists of both internal and external commands that perform
various tasks and functions.
Here is a list of some commonly used internal and external DOS commands with examples:

Internal Commands:
1. CD (Change Directory) - Changes the current directory.
Example: `cd \Windows\System32` - Changes the current directory to the System32 folder
in the Windows directory.
2. DIR (Directory) - Displays a list of files and folders in the current directory.
Example: `dir /w` - Displays a list of files and folders in the current directory in a wide format.
3. COPY - Copies one or more files from one location to another.
Example: `copy C:\Data\File.txt D:\Backup\File.txt` - Copies the file named "File.txt" from
the "C:\Data" directory to the "D:\Backup" directory.
4. DEL (Delete) - Deletes one or more files.
Example: `del C:\Data\File.txt` - Deletes the file named "File.txt" from the "C:\Data" directory.
5. MD (Make Directory) - Creates a new directory.
Example: `md C:\NewFolder` - Creates a new directory named "NewFolder" in the "C:\"
directory.

External Commands:
1. FORMAT - Formats a disk or drive.
Example: `format C:` - Formats the C: drive.
2. XCOPY - Copies one or more files or directories, including subdirectories.
Example: `xcopy C:\Data D:\Backup /E /H /Y` - Copies the "Data" directory and all its
subdirectories to the "Backup" directory on the D: drive, including hidden files, and
overwriting existing files without prompting.
3. CHKDSK (Check Disk) - Checks the disk for errors.
Example: `chkdsk C: /F` - Checks the C: drive for errors and fixes any errors found.
4. TREE - Displays the directory structure of a drive or path.
Example: `tree C:\Windows\System32` - Displays the directory structure of the System32
folder in the Windows directory.
5. NET - Displays or modifies network settings.
Example: `net view` - Displays a list of all shared resources on the network.
EXPERIMENT NO. 3

AIM:- Write any five Linux commands with using examples.

1. 'ls': Lists the contents of a directory.


Example: ls /home/user/Documents lists the contents of the Documents folder of the user.
2. 'cd': Changes the current directory.
Example: cd /home/user changes the current directory to the user folder.
3.'mkdir': Creates a new directory.
Example: mkdir new_folder creates a new folder called "new_folder".
4. 'touch': Creates a new file or updates the modification timeof an existing file.
Example: touch new_file.txt creates a new file called "new_file.txt".
5. 'rm': Removes a file or directory.
Example: rm file.txt removes the file called "file.txt".
6. 'rmdir': Removes an empty directory.
Example: rmdir folder removes the folder called "folder".
7. 'cp': Copies a file or directory.
Example: cp file.txt /home/user/Documents copies the file "file.txt" to the documents folder of the
user.
8. 'mv': Moves or renames a file or directory.
Example: mv file.txt new_folder/file_new.txt moves the file "file.txt" to the "new_folder"
directory and renames it to "file_new.txt"
9. 'cat': Displays the contents of a file.
Example: cat file.txt displays the contents of the file called "file.txt".
10. 'grep': Searches for a pattern in a file or input.
Example: grep "hello" file.txt searches for the word "hello" in the file called "file.txt".
EXPERIMENT NO. 4

AIM:- Linux command “rmdir/s foldername” to delete folder having files in it.

@echo off
Set /p folder_name=”Enter the name of the folder you want to delete : ”
If exist %folder_name% (
echo Deleting %folder_name% and all its contents…
rmdir /s /q %folder_name%
echo Folder %folder_name% deleted successfully.
)
else
(
echo Folder %folder_name% does not exist.
)
EXPERIMENT 5.

AIM: Write a program in Linux that takes two numbers as input and displays their
sum on the screen.

Calculating the sum of two integers (Numbers) in a shell script is pretty simple as in other
programming languages.
Here is an example of a shell script,which takes input from the user at run time. Then
calculate the sum of given numbers and store to a variable and show the results.

read –p “enter first number : ” num 1

read –p “enter second number : ” num 2

sum=$(( $sum1 + $sum2 ))

echo “ Sum is :$sum ”


EXPERIMENT.NO.6

AIM: Simulate all file allocation strategies for Sequential storage.


FILE ALLOCATION STRATEGIES
A) SEQUENTIAL:
Themostcommonformoffilestructureisthesequentialfileinthistypeoffile,afixedformatisusedforr
ecords.Allrecords(ofthesystem)havethesamelength,consistingofthesamenumberoffixedlengthf
ieldsinaparticularorderbecausethelengthandpositionofeachfieldareknown,onlythevaluesoffiel
dsneedtobestored,thefieldnameandlengthforeachfieldareattributesofthefilestructure.

SOURCE CODE :
#include<stdio.h>
main()
{
intf[50],i,st,j,len,c,k;
clrscr();
for(i=0;i<50;i++)
f[i]=0;X:
printf("\n Enter the starting block & length of file");
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++)
if(f[j]==0)
{
printf("\n%d->%d",j,f[j]);
}
else
{
printf("Block already allocated");
break;
}

if(j==(st+len))
printf("\nthe file is allocated to disk");
printf("\n if u want to enter more files?(y-1/n-0)");
scanf("%d",&c);
if(c==1)
gotoX;
else
exit();
getch();
{
}

OUTPUT:
Enterthestartingblock&lengthoffile
4104->1
5->1
6->1
7->1
8->1
9->1
10->1
11->1
12->1
13->1
The file is allocated to disk.
EXPERIMENT NO :7

AIM: To implement linked file allocation strategy.

DESCRIPTION:
In the chained method file allocation table contains a field which points to starting block of
memory .From it for each block pointer is kept on ext successive block .Hence, there is no
external fragmentation.

SOURCE CODE :

#include<stdio.h>main()
{
intf[50],p,i,j,k,a,st,len,n,c;
clrscr();
for(i=0;i<50;i++)f[i]=0;
printf("Enterhowmanyblocksthatarealreadyallocated");
scanf("%d",&p);printf("\nEntertheblocksno.sthatarealreadyallocated");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
X:
printf("Enterthestartingindexblock&length");
scanf("%d%d",&st,&len);k=len;
for(j=st;j<(k+st);j++)
{

if(f[j]==0)
{f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n%d>fileisalreadyallocated",j)
k++;
}
}
printf("\n If u want to enter one more
file?(yes1/n0)");
scanf("%d",&c);
if(c==1)
gotoX;
else
xit();
getch();}
OUTPUT:
Enter how many blocks that are already allocated 3
Enter the blocks no. that are already allocated 479
Enter the starting index block & length 37
3->1
4->1 file is already allocated5->1
6->1
7->1
file is already allocated
8->1
9->1
File is already allocated
10->1
11->1
12->1
EXPERIMENT NO. O8:

AIM: To implement deadlock prevention technique

Banker‘sAlgorithm:
Bankers algorithm in Operating System is used to avoid deadlock and for resource allocation safely to
each process in the system. As the name suggests, it is mainly used in the banking system to check
whether the loan can be sanctioned to a person or not.
SOURCE CODE :

#include<stdio.h>
#include<conio.h>
Void main()
{
Char job[10][10];
Int time[10],avail,tem[10],temp[10];
Int safe[10];
Int ind=1,i,j,q,n,t;
clrscr();
printf("Enter no of jobs:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter name and time:");
scanf("%s%d",&job[i],&time[i]);
}
printf("Enter the avail able resources:");
scanf("%d",&avail);
for(i=0;i<n;i++)
{
temp[i]=time[i];
tem[i]=i;
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(temp[i]>temp[j])
{
t=temp[i];
temp[i]=temp[j];
temp[j]=t
;t=tem[i];
tem[i]=tem[j];
tem[j]=t;
}
}
for(i=0;i<n;i++)
{
q=tem[i];
if(time[q]<=avail)
{
safe[ind]=tem[i];
avail=avail-tem[q];
//printf("%s",job[safe[ind]]);
ind++;

}
else
{
printf("Nosafesequence\n");
}
}
printf("Safesequenceis:");
for(i=1;i<ind;i++)
printf("%s%d\n",job[safe[i]],time[safe[i]]);
getch();
}

OUTPUT:
Enter no of jobs:4
Enter name and time:A1 Enter name and time:B4 Enter name and time:C2 Enter name and time:D3
Enter the available resources:20 Safe sequence is:A1,C2,D3,B4.
EXPERIMENTNO: - 9

AIM: Implement the page replacement algorithms for FIFO.

PAGE REPLACEMENT ALGORITHMS

FIRST IN FIRST OUT :

AIM: To implement FIFO pager replacement technique.

SOURCE CODE :

#include<stdio.h>
#include<conio.h>
intfr[3];
void main()
{
Void display();
Int i,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2};
Int flag1=0,flag2=0,pf=0,frsize=3,top=0;
clrscr();
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<12;j++)
{
flag1=0;
flag2=0;
for(i=0;i<12;i++)
{
If (fr[i]==page[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i<frsize;i++)
{
if(fr[i]==-1)
{
fr[i]=page[j];
flag2=1;
break;
}}}
if(flag2==0)
{
fr[top]=page[j];
top++;
pf++;
if(top>=frsize)top=0;
}
display();
}
printf("Number of page faults:%d",pf);
getch();
}
Void display()
{

Int i;
printf("\n");
for(i=0;i<3;i++)
printf("%d\t",fr[i]);
}

OUTPUT:
2 -1-1
23-1
23-1
23 1
53 1
52 1
52 4
52 4
32 4
32 4
35 4
35 2
Number of page faults:
EXPERIMENT NO :. 10

AIM:. Implement Paging technique for memory management.

SOURCE CODE :

/*Memory Allocation with Paging Technique*/

#include<studio.h>
#include<conio.h>
Structpstruct
{
intfno;
intpbit;
}
ptable[10];
int pmsize,lmsize,psize,frame,page,ftable[20],
frameno;voidinfo()

printf("\n\n MEMORY MANAGEMENT USING PAGING\n\n");


printf("\n\nEnter the Size of Physical memory:");
scanf("%d",&pmsize);
printf("\n\n Enter the size of Logical memory:");
scanf("%d",&lmsize);
printf("\n\n Enter the partition size:");
scanf("%d",&psize);
frame=(int)pmsize/psize;
page=(int)lmsize/psize;
printf("\n The physical memory is divided into%dno.offrames\n",frame);
printf("\n The Logical memory is divided into%dno.ofpages",page);

}
Void assign()
{
int;
for(i=0;i<page;i++)
{
ptable[i].fno=-1;
ptable[i].pbit=-1;
}
for(i=0;i<frame;i++)
ftable[i]=32555;
for(i=0;i<page;i++)
{
printf("\n\n Enter the Frame number where page%dmust be placed:",i);
scanf("%d",&frameno);
ftable[frameno]=i;
if(ptable[i].pbit=1)
{
ptable[i].fno=frame no;
ptable[i].pbit=1;
}
}
getch();
clrscr();
printf("\n\nPAGETABLE\n\n");
printf("Page Address Frame No. Presence Bit\n\n");
for(i=0;i<page;i++)
printf("%d\t\t%d\t\t%d\n",i,ptable[i].fno,ptable[i].pbit);
printf("\n\n\n\tFRAME TABLE\n\n");
printf("Frame Address Page No\n\n");
for(i=0;i<frame;i++)
printf("%d\t\t%d\n",i,ftable[i]);
}
Void cphyaddr()
{
intladdr,paddr,disp,phyaddr,baddr;
getch();
clrscr();
printf("\n\n\n\tProcess to create the Physical Address\n\n");
printf("\n Enter the Base Address:");
scanf("%d",&baddr);
printf("\nEnter the Logical Address:");
scanf("%d",&laddr);
paddr=laddr/ psize;
disp=laddr%psize;
if(ptable[paddr].pbit=1)
phyaddr=baddr+(ptable[paddr].fno*psize)+disp;
printf("\nThe Physical Address where the instruction present:%d",phyaddr);
}
Void main()
{
clrscr();
info();
assign();
cphyaddr();
getch();
}

OUTPUT:

MEMORY MANAGEMENT USING PAGING


Enter the Size of Physical memory:16
Enter the size of Logical memory:8
Enter the partition size:2
The physical memory is divided into 8 no.of frames The Logical memory is divided into 4 no. of
pages
Enter the Frame number where page 0 must be placed :5
Enter the Frame number where page 1 must be placed:6
Enter the Frame number where page2 must be placed: 7
Enter the Frame number where page3 must be placed: 2

PAGETABLE

Page Address Frame No. Presence Bit

0 5 1

1 6 1
2 7 1
3 2 1
FRAMETABLE

Frame Address Page No


0 3555
1 32555
2 3
3 32555
4 32555
5 0
6 1
7 2

Process to create the Physical Address Enter the Base Address: 1000
Enter the Logical Address:3
The Physical Address where the instruction present:1013

You might also like