Lab Manual OS
Lab Manual OS
6. Mobile OS
Mobile operating systems are those OS which is especially that are designed to
power smartphones, tablets, and wearables devices.
Some most famous mobile operating systems are Android and iOS, but others
include BlackBerry, Web, and watchOS.
Content:
Hardware requirements: The most common set of requirements defined by
any operating system or software application is the physical computer
resources, also known as hardware, A hardware requirements list is often
accompanied by a hardware compatibility list (HCL), especially in case of
operating systems.
1. Windows 10
2. WINDOWS XP
The minimum hardware requirements for Windows XP Home Edition are:
Pentium 233- megahertz (MHz) processor or faster (300 MHz is recommended)
3. UNIXOS
RAM:1 GB
Processor: IBM 604e processor with a clock speed of 375 MHz or faster
Free disk space: /tmp must have 1 GB free disk space. If Tivoli Identity Manager
installs, Web Sphere Application Server, (WAS_HOME) must have 800 MB free
disk space and /var must have 300 MB free disk space. Allocate 500 MB for
/itim45.
4. LINUX
Content:
The interface between a process and an operating system is provided by system
calls. In general, system calls are available as assembly language instructions.
They are also included in the manuals used by the assembly level programmers.
access() This checks if a calling process has access to the required file
chdir()
The chdir command changes the current directory of the system
pause() The pause call suspends a file until a particular signal occurs.
alarm() The alarm system call sets the alarm clock of a process
AIM – Write a program in C to implement First Come First Serve (FCFS) Scheduling
Algorithm
CODE –
int main()
{
int
n,bt[20],wt[20],tat[20],avwt=0,avt
at=0,i,j; printf("Enter total number of
processes(maximum 20):"); scanf("%d",&n);
//calculatingturnaroundtime
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
}
avwt/=i; avtat/=i;
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d\n",avtat);
return 0;
}
OUTPUT –
Enter total number of processes(maximum
P[1] : 4
P[2] : 2
P[3] : 6
1 40 4
2 2 4 6
3 6 6 12
CODE –
#include<stdio.h>
int main()
{
int A[100][4]; // Matrix for storing Process Id, Burst
// Time, Average Waiting Time &
Average // Turn Around Time.
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.
OUTPUT –
Enter number of process: 5
Enter Burst Time:
P1: 4
P2: 12
P3: 6
P4: 3
P5: 4
Proces Burst Waiting Turn Around
s Time Time Time
P4 3 0 3
P1 4 3 7
P5 4 7 11
P3 6 11 17
P2 12 17 29
struct process
{
int WT,AT,BT,TAT,PT;
};
struct process a[10];
int main()
{
int n,temp[10],t,count=0,short_p;
float total_WT=0,total_TAT=0,Avg_WT,Avg_TAT;
printf("Enter the number of the process\n");
scanf("%d",&n);
printf("Enter the arrival time , burst time and priority of the process\n");
printf("Arrival Time\t Burst Time\t Priority\n");
for(int i=0;i<n;i++)
{
scanf("%d%d%d",&a[i].AT,&a[i].BT,&a[i].PT);
// copying the burst time in a temp array for futher use
temp[i]=a[i].BT;
}
// we initialize the burst time of a process with maximum
a[9].PT=10000;
for(t=0;count!=n;t++)
{
short_p=9;
for(int i=0;i<n;i++)
{
if(a[short_p].PT>a[i].PT && a[i].AT<=t && a[i].BT>0)
{
short_p=i;
}
}
a[short_p].BT=a[short_p].BT-1;
//totalcalculation
total_WT=total_WT+a[short_p].WT;
total_TAT=total_TAT+a[short_p].TAT;
}
}
Avg_WT=total_WT/n;
Avg_TAT=total_TAT/n;
// printing of the answer
printf("Proocess ID\t Waiting Time\t Turn Around Time\n");
for(int i=0;i<n;i++)
{
printf("%d %d\t%d\n",i+1,a[i].WT,a[i].TAT);
}
OUTPUT:
Enter the number of the process 3
Enter the arrival time , burst time and priority of the process
1 5 1
2 2 2
Turn Around
Process ID Waiting
Time
Time
1 7 10
2 0 5
3 4 6
int main()
temp[10];
scanf("%d", &limit);
x = limit;
scanf("%d", &arrival_time[i]);
scanf("%d", &burst_time[i]);
temp[i] = burst_time[i];
Timen");
for(total = 0, i = 0; x != 0;){
temp[i] = 0;
counter = 1;
{ x--;
counter = 0;
if(i == limit - 1)
{ i = 0;
}
else if(arrival_time[i + 1] <= total)
{ i++;
else{
i = 0;
}}
average_wait_time=wait_time*1.0/limit;
return 0;
OUTPUT –
Enter Total Number of Processes: 4
Enter Details of Process[1]
Arrival Time: 2
Burst Time: 4
Arrival Time: 4
Burst Time: 5
Enter Details of Process[3
] Arrival Time: 6
Burst Time: 4
] Arrival Time: 3
Burst Time: 6
Content: The allocation methods define how the files are stored in the disk
blocks. There are three main disk space or file allocation methods.
Contiguous
Allocation Linked
Allocation Indexed
Allocation
Program
SEQUENTIAL FILE ALLOCATION
#include<conio.h>
#include<stdio.h>
void main()
{
int f[50], i, st, len, j, c, k,
count = 0; clrscr();
for(i=0;i<50;i++)
f[i]=0;
printf("Files Allocated are : \n");
count=0;
printf(“Enter starting block and length of files: ”);
scanf("%d%d", &st,&len);
for(k=st;k<(st+len);k++)
if(f[k]==0) count++; if(len==count)
{
for(j=st;j<(st+len);j++)
if(f[j]==0)
{
f[j]=1;
printf("%d\t%d\n",j,f[j]);
}
if(j!=(st+len-1))
printf(” The file is allocated to disk\n");
}
else
printf(” The file is not allocated \n");
printf("Do you want to enter more file(Yes - 1/No - 0)"); scanf("%d",
&c);
if(c==1)
goto x;
else
exit();
getch();
}
Program Output:
Files Allocated are :
Enter starting block and length
of files: 14 3 14 1
15 1
16 1
The file is allocated to disk
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files: 14 1 The file is not allocated
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files: 14 4
The file is not allocated
Do you want to enter more file(Yes - 1/No – 0)
LINKED FILE ALLOCATION
#include<conio.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
int f[50], p,i, st, len, j, c, k, a;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
printf("Enter how many blocks already allocated: ");
scanf("%d",&p);
printf("Enter blocks already allocated: ");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
printf("Enter index starting block and length: ");
scanf("%d%d", &st,&len);
k=len;
if(f[st]==0)
{
for(j=st;j<(st+k);j++)
{
if(f[j]==0)
{ f[j]=1;
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
exit(0);
getch();
}
Program Output:
Enter how many blocks already allocated: 3
Enter blocks already allocated: 1 3 5
Enter index starting block and length: 2 2 2 >1
3
4 Block is already
allocated 4 >1
Do you want to enter more file(Yes - 1/No - 0)0
INDEXED ALLOCATION TECHNIQUE
i#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int f[50], index[50],i, n, st, len, j, c, k, ind,count=0;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
x:printf("Enter the index block: ");
scanf("%d",&ind);
if(f[ind]!=1)
{
printf("Enter no of blocks needed and no of files for the index %d on the disk
: \n", ind);
scanf("%d",&n);
}
else
{
printf("%d index is already allocated \n",ind);
goto x;
}
y: count=0;
for(i=0;i<n;i++)
{
scanf("%d", &index[i]);
if(f[index[i]]==0)
count++;
}
if(count==n)
{
for(j=0;j<n;j++)
f[index[j]]=1;
printf("Allocated\n");
printf("File Indexed\n");
for(k=0;k<n;k++)
printf("%d >%d : %d\n",ind,index[k],f[index[k]]);
}
else
{
printf("File in the index is already allocated \n");
printf("Enter another file indexed");
goto y;
}
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if(c==1)
goto x;
else
exit(0);
getch();
}
Program Output:
Enter the index block: 5
Enter no of blocks needed and no of files for the
index 5 on the disk : 4
1234
Allocated
File
Indexed
5 >1 :
1
5-------->2 : 1
5-------->3 : 1
5-------->4 : 1
Do you want to enter more file(Yes - 1/No - 0)1
Enter the index block: 4
5 index is already allocated
6 Enter the index block: 6
Enter no of blocks needed and no of files for the
index 6 on the disk : 2
78
Allocated File Indexed 6
>7 : 1
6-------->8 : 1
Do you want to enter more file(Yes - 1/No - 0)0
EXPERIMENT – 8
AIM – Write a Programme in C to implement Contiguous Allocation
Techniques
1. Worst fit
2. Best fit
3. First fit
CODE –
Worst fit
#include<iostream>
#include<memset>
blockSize[wstIdx] -= processSize[i];
}
}
printf( "\nProcess No.\tProcess Size\tBlock no.\n");
for (int i = 0; i < n; i++)
{
printf("%d \t\t %d \t\t",i+1,processSize[i]);
if (allocation[i] != -1)
printf(“%d”, allocation[i] + 1);
else
printf("Not Allocated");
printf(“\n”);
}
}
Best fit
void bestFit(int blockSize[], int m, int processSize[], int n)
{
prinf(“Best fit: \n”);
int allocation[n];
memset(allocation, -1, sizeof(allocation));
for (int i=0; i<n; i++)
{
int bestIdx = -1;
for (int j=0; j<m; j++)
{
if (blockSize[j] >= processSize[i])
{
if (bestIdx == -1) bestIdx = j;
else if (blockSize[bestIdx] > blockSize[j])
bestIdx = j;
}
}
if (bestIdx != -1)
{
allocation[i] = bestIdx;
blockSize[bestIdx] -= processSize[i];
}
}
if (allocation[i] != -1)
printf(“%d”,allocation[i] + 1);
else
printf("Not Allocated");
printf(“\n”);
}
}
First fit
void firstFit(int blockSize[], int m, int processSize[], int n)
{
printf(“First Fit: \n”);
int allocation[n];
memset(allocation, -1, sizeof(allocation));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (blockSize[j] >= processSize[i])
{
allocation[i] = j;
blockSize[j] -= processSize[i];
break;
}
}
}
if (allocation[i] != -1)
printf(“%d”,allocation[i] + 1);
else
printf( "Not Allocated");
printf(“\n”);
}
}
void main()
{
return 0 ;
OUTPUT
T–
Worst fit
Process Process Block no.
No. Size
1 212 5
2 417 2
3 112 5
4 426 Not Allocated
Best fit:
Process Process Block no.
No. Size
1 212 4
2 417 2
3 112 3
4 426 5
First Fit:
Process Process Block no.
No. Size
1 212 2
2 417 5
3 112 2
4 426 Not Allocated
EXPERIMENT-9
#include<conio.h>
void main()
{
int f[50], i, st, len, j, c, k, count = 0;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
printf("Files Allocated are : \n"); x:
count=0;
printf(“Enter starting block and length of files: ”);
scanf("%d%d",&st,&len);
for(k=st;k<(st+len);k++)
if(f[k]==0) count++;
if(len==count)
{
for(j=st;j<(st+len);j++)
if(f[j]==0)
{ f[j]=1;
printf("%d\t%d\n",j,f[j]);
}
if(j!=(st+len-1))
printf(” The file is allocated to disk\n");
}
else
printf(” The file is not allocated \n");
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if(c==1)
goto x;
else
exit();
getch();
}
OUTPUT –
Files Allocated are :
Enter starting block and length of files: 14 3 14 1
15 1
16 1
The file is allocated to disk
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files: 14 1
The file is not allocated
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files: 14 4
The file is not allocated
Do you want to enter more file(Yes - 1/No - 0)0
Experiment No :10
AIM – Write a Program in C to implement Resource Allocation Graph ( RAG).
CODE –
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int proc,res,i,j,row=0,flag=0;
int main()
{
printf("\nEnter the number of Processes: ");
scanf("%d",&proc);
printf("\nEnter the number of Resources: ");
scanf("%d",&res);
printf("\nEnter the Process Matrix:\n");
for(i=0;i<proc;i++)
for(j=0;j<res;j++)
scanf("%d",&pro[i][j]);
scanf("%d",&req[i][j]);
row=0;
while(1) {
for(i=0;i<res;i++){
if(pro[row][i]==1){
if(st_pro[row][i]>1 && flag==1)
{ printf("\nDeadlock Occured");
return 0;
}
st_pro[row][i]++;
row=i; break;
}}
for(i=0;i<proc;i++){
if(req[row][i]==1){
if(st_req[row][i]>1)
{ printf("\nDeadlock Occured");
return 0;
}
st_req[row][i]++;
row=i;
flag=1;
break;
}} }
#include<stdio.h>
#include<conio.h>
void main()
{
int
k=0,output[10],d=0,t=0,ins[5],i,avail[5],allocated[10][5],need[10][5],MAX[10][5],
pno,P[10], j,rz, count=0;
clrscr();
printf("\n Enter the number of resources : ");
scanf("%d", &rz);
printf("\n enter the max instances of each resources\n");
for (i=0;i<rz;i++) {
avail[i]=0;
printf("%c= ",(i+97));
scanf("%d",&ins[i]);
}
printf("\n Enter the number of processes : ");
scanf("%d", &pno);
printf("\n Enter the allocation matrix \n ");
for (i=0;i<rz;i++)
printf(" %c",(i+97));
printf("\n");
for (i=0;i <pno;i++) {
P[i]=i;
printf("P[%d] ",P[i]);
for (j=0;j<rz;j++) {
scanf("%d",&allocated[i][j]);
avail[j]+=allocated[i][j];
}
}
printf("\nEnter the MAX matrix \n ");
for (i=0;i<rz;i++) {
printf(" %c",(i+97));
avail[i]=ins[i]-avail[i];
}
printf("\n");
for (i=0;i <pno;i++) {
printf("P[%d] ",i);
for (j=0;j<rz;j++)
scanf("%d", &MAX[i][j]);
}
printf("\n");
A: d=-1;
for (i=0;i <pno;i++) {
count=0;
t=P[i];
for (j=0;j<rz;j++) {
need[t][j] = MAX[t][j]-allocated[t][j];
if(need[t][j]<=avail[j])
count++;
}
if(count==rz) {
output[k++]=P[i];
for (j=0;j<rz;j++)
avail[j]+=allocated[t][j];
}
else
P[++d]=P[i];
}
if(d!=-1) {
pno=d+1;
goto A;
}
printf("\t <"); for
(i=0;i<k;i++)
printf(" P[%d] ",output[i]);
printf(">");
getch();
}
EXPERIMENT – 12
CODE –
#include <stdio.h>
#include <stdlib.h>
// Main function
int main() {
struct Graph* rag = createGraph(4);
addEdge(rag, 0, 1);
addEdge(rag, 0, 2);
addEdge(rag, 1, 2);
addEdge(rag, 2, 0);
addEdge(rag, 2, 3);
addEdge(rag, 3, 3);
struct Graph* wfg = convertRAGtoWFG(rag);
printf("Wait-for-Graph:\n");
printWFG(wfg);
return 0;
}
EXPERIMENT – 13
AIM- Write a program in C to implement the solution for bounded
buffer problem using inter process communication techniques-
Semaphores
#include <stdio.h>
//Item produced
x++;
printf("\nProducer produces" "item %d",x);
++mutex;
}
// Driver Code
int main()
{
int n, i;
printf("\n1. Press 1 for Producer" "\n2. Press 2 for Consumer" "\n3.
Press 3 for Exit");
// Using '#pragma omp parallel for can give wrong value due to
synchronization issues.
// 'critical' specifies that code is executed by only one thread at a time i.e., only
one thread enters
// the critical section at a given
time #pragma omp critical
// Exit Condition
case 3:
exit(0);
break;
}
}
}
OUTPUT
EXPERIMENT – 14
AIM- Write a program in C to implement the solution for reader writer
problem using inter process communication techniques-Semaphores
#include<semaphore.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<pthread.h>
sem_t x,y;
pthread_t tid;
pthread_t
writerthreads[100],readerthreads[100];
int readercount = 0;
void *reader(void* param)
{
sem_wait(&x);
readercount++;
if(readercount==1)
sem_wait(&y);
sem_post(&x);
printf("%d reader is inside\n",readercount);
usleep(3);
sem_wait(&x);
readercount--;
if(readercount==0)
{
sem_post(&y);
}
sem_post(&x);
printf("%d Reader is leaving\n",readercount+1);
return NULL;
}
OUTPUT –
1 reader is inside
Writer is trying to
enter 2 reader is
inside
2 Reader is leaving
2 reader is inside
Writer is trying to
enter 2 Reader is
leaving
1 Reader is leaving