0% found this document useful (0 votes)
2 views

OS ALL output

The document discusses an experiment conducted to test a specific hypothesis. It outlines the methodology, results, and conclusions drawn from the findings. The experiment aims to contribute to the understanding of the topic in question.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

OS ALL output

The document discusses an experiment conducted to test a specific hypothesis. It outlines the methodology, results, and conclusions drawn from the findings. The experiment aims to contribute to the understanding of the topic in question.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Experiment 1

Experiment 2
EXP3

Example of fork() in C

#include <sys/types.h>
#include <unistd.h>
int main()
{
pid_t p = fork();
if(p<0){
perror("fork fail");
exit(1);
}
printf("Hello world!, process_id(pid) = %d \n",getpid());
return 0;
}

Output
Hello world!, process_id(pid) = 31
Hello world!, process_id(pid) = 32
Example 2: Calculate the number of times hello is printed.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
fork();
fork();
fork();
printf("hello\n");
return 0;

hello
hello
hello
hello
hello
hello
hello
hello

}
EXP 4 FCFS CPU SCHEDULING
// C program for implementation of FCFS scheduling
#include <stdio.h>
void findWaitingTime( int processes[ ] , int n ,
int bt[ ], int wt[ ])
{
wt[ 0 ] = 0;
for (int i = 1 ; i < n ; i++)
wt[ i ] = bt[ i - 1 ] + wt[ i - 1 ] ;
}
void findTurnAroundTime ( int processes[ ], int n,
int bt[ ] , int wt [ ] , int tat[ ] )
{
for ( int i = 0 ; i < n ; i++ )
tat[i] = bt[i] + wt[i];
}
void findavgTime(int processes[], int n, int bt[])
{
int wt[n], tat[n], total_wt = 0, total_tat = 0;
findWaitingTime(processes, n, bt, wt);
findTurnAroundTime(processes, n, bt, wt, tat);
printf("Processes Burst time Waiting time Turn around time\n");
for (int i = 0; i < n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
printf(" %d ", (i + 1));
printf(" %d ", bt[i]);
printf(" %d", wt[i]);
printf(" %d\n", tat[i]);
}
int s = (float)total_wt / (float)n;
int t = (float)total_tat / (float)n;
printf("Average waiting time = %d", s);
printf("\n");
printf("Average turn around time = %d ", t);
}
int main()
{
// process id's
int processes[] = {1, 2, 3};
int n = sizeof processes / sizeof processes[0];
int burst_time[] = {10, 6, 9};
findavgTime(processes, n, burst_time);
return 0;
}
EXP 5 Priority Preemptive Algorithm
#include<stdio.h>
#include<stdlib.h>
struct process {
int process_id;
int burst_time;
int priority;
int waiting_time;
int turnaround_time;
};
void find_waiting_time(struct process[], int, int[]);
void find_turnaround_time(struct process[], int, int[], int[]);
void find_average_time(struct process[], int);
void priority_scheduling(struct process[], int);
int main()
{
int n, i;
struct process proc[10];
printf("Enter the number of processes: ");
scanf("%d", &n);
for(i = 0; i< n; i++)
{
printf("\nEnter the process ID: ");
scanf("%d", &proc[i].process_id);
printf("Enter the burst time: ");
scanf("%d", &proc[i].burst_time);
printf("Enter the priority: ");
scanf("%d", &proc[i].priority);
}
priority_scheduling(proc, n);
return 0;
}
void find_waiting_time(struct process proc[], int n, int wt[])
{
int i;
wt[0] = 0;
for(i = 1; i< n; i++)
{
wt[i] = proc[i - 1].burst_time + wt[i - 1];
}
}
void find_turnaround_time(struct process proc[], int n, int wt[], int tat[])
{
int i;
for(i = 0; i< n; i++)
{
tat[i] = proc[i].burst_time + wt[i];
}
}
void find_average_time(struct process proc[], int n)
{
int wt[10], tat[10], total_wt = 0, total_tat = 0, i;
find_waiting_time(proc, n, wt);
find_turnaround_time(proc, n, wt, tat);
printf("\nProcess ID\tBurst Time\tPriority\tWaiting Time\tTurnaround Time");
for(i = 0; i< n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", proc[i].process_id, proc[i].burst_time, proc[i].priority, w
t[i], tat[i]);
}
printf("\n\nAverage Waiting Time = %f", (float)total_wtotal_wt/n);
printf("\nAverage Turnaround Time = %f\n", (float)total_tat/n);
}
void priority_scheduling(struct process proc[], int n)
{
int i, j, pos;
struct process temp;
for(i = 0; i< n; i++)
{
pos = i;
for(j = i + 1; j < n; j++)
{
if(proc[j].priority< proc[pos].priority)
pos = j;
}
temp = proc[i];
proc[i] = proc[pos];
proc[pos] = temp;
}
find_average_time(proc, n);
}
EXP 6 Round robin Preemptive Algorithm
#include <stdio.h>
void findWaitingTime(int processes[], int n, int bt[], int wt[], int quantum) {
int rem_bt[n];
for (int i = 0; i < n; i++)
rem_bt[i] = bt[i];
int t = 0;
while (1) {
int done = 1;
for (int i = 0; i < n; i++) {
if (rem_bt[i] > 0) {
done = 0;
if (rem_bt[i] > quantum) {
t += quantum;
rem_bt[i] -= quantum;
} else {
t += rem_bt[i];
wt[i] = t - bt[i];
rem_bt[i] = 0;
}
}
}

if (done == 1)
break;
}
}

void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[]) {
for (int i = 0; i < n; i++)
tat[i] = bt[i] + wt[i];
}

void findAvgTime(int processes[], int n, int bt[], int quantum) {


int wt[n], tat[n];
findWaitingTime(processes, n, bt, wt, quantum);
findTurnAroundTime(processes, n, bt, wt, tat);
printf("\nProcess\tBurst Time\tWaiting Time\tTurnaround Time\n");
int total_wt = 0, total_tat = 0;
for (int i = 0; i < n; i++) {
total_wt += wt[i];
total_tat += tat[i];
printf("P%d\t%d\t\t%d\t\t%d\n", processes[i], bt[i], wt[i], tat[i]);
}
printf("\nAverage waiting time = %.2f", (float)total_wt / n);
printf("\nAverage turnaround time = %.2f\n", (float)total_tat / n);
}
int main() {
int n, quantum;
printf("Enter number of processes: ");
scanf("%d", &n);
int processes[n], burst_time[n];
for (int i = 0; i < n; i++) {
processes[i] = i + 1;
printf("Enter burst time for process P%d: ", processes[i]);
scanf("%d", &burst_time[i]);
}
printf("Enter time quantum: ");
scanf("%d", &quantum);
findAvgTime(processes, n, burst_time, quantum);
return 0;
}
EXP 7 Banker Algorithm
#include <stdio.h>
void main() {
int k = 0, a = 0, b = 0;
int instance[5], availability[5];
int allocated[10][5], need[10][5], MAX[10][5];
int process, P[10], op[10];
int no_of_resources, cnt = 0, i, j;

printf("\nEnter the number of resources: ");


scanf("%d", &no_of_resources);

printf("\nEnter the max instances of each resource:\n");


for (i = 0; i < no_of_resources; i++) {
availability[i] = 0;
printf("%c = ", (i + 97)); // a, b, c, ...
scanf("%d", &instance[i]);
}

printf("\nEnter the number of processes: ");


scanf("%d", &process);

printf("\nEnter the allocation matrix:\n");


for (i = 0; i < no_of_resources; i++)
printf(" %c", (i + 97));
printf("\n");

for (i = 0; i < process; i++) {


P[i] = i;
printf("P[%d] ", P[i]);
for (j = 0; j < no_of_resources; j++) {
scanf("%d", &allocated[i][j]);
availability[j] += allocated[i][j];
}
}

printf("\nEnter the MAX matrix:\n");


for (i = 0; i < no_of_resources; i++) {
printf(" %c", (i + 97));
availability[i] = instance[i] - availability[i];
}
printf("\n");

for (i = 0; i < process; i++) {


printf("P[%d] ", i);
for (j = 0; j < no_of_resources; j++) {
scanf("%d", &MAX[i][j]);
}
}

printf("\nSafe Sequence: < ");


A:
a = -1;
for (i = 0; i < process; i++) {
cnt = 0;
b = P[i];
for (j = 0; j < no_of_resources; j++) {
need[b][j] = MAX[b][j] - allocated[b][j];
if (need[b][j] <= availability[j])
cnt++;
}
if (cnt == no_of_resources) {
op[k++] = P[i]; // Add to safe sequence
for (j = 0; j < no_of_resources; j++)
availability[j] += allocated[b][j];
} else {
P[++a] = P[i];
}
}

if (a != -1) {
process = a + 1;
goto A;
}

for (i = 0; i < k; i++)


printf("P[%d] ", op[i]);
printf(">\n");
}
EXP 8 First fit
// C implementation of First - Fit algorithm
#include <stdio.h>
void firstFit(int blockSize[], int m, int processSize[], int n) {
int i, j;
int allocation[n];
for (i = 0; i < n; i++) {
allocation[i] = -1;
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (blockSize[j] >= processSize[i]) {
allocation[i] = j;
blockSize[j] -= processSize[i];
break;
}
}
}

printf("\nProcess No.\tProcess Size\tBlock no.\n");


for (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");
}
}
int main() {
int blockSize[] = {100, 500, 200, 300, 600};
int processSize[] = {212, 417, 112, 426};
int m = sizeof(blockSize) / sizeof(blockSize[0]);
int n = sizeof(processSize) / sizeof(processSize[0]);
firstFit(blockSize, m, processSize, n);
return 0;
}
EXP 9 FIFO PAGE REPLACEMENT ALGORITHM
Program:
#include <stdio.h>
int main()
{
int incomingStream[] = {4, 1, 2, 4, 5};
int pageFaults = 0;
int frames = 3;
int m, n, s, pages;
pages = sizeof(incomingStream)/sizeof(incomingStream[0]);
printf("Incoming\tFrame 1\t\tFrame 2\t\tFrame 3\n");
int temp[frames];
for(m = 0; m < frames; m++)
{
temp[m] = -1;
}
int next_to_replace = 0;
for(m = 0; m < pages; m++)
{
s = 0;
for(n = 0; n < frames; n++)
{
if(incomingStream[m] == temp[n])
{
s++;
break;
}
}
if(s == 0)
{
temp[next_to_replace] = incomingStream[m];
next_to_replace = (next_to_replace + 1) % frames;
pageFaults++;
}
printf("%d\t\t", incomingStream[m]);
for(n = 0; n < frames; n++) {
if(temp[n] != -1)
printf("%d\t\t", temp[n]);
else
printf("-\t\t");
}
printf("\n");
}
printf("\nTotal Page Faults:\t%d\n", pageFaults);
return 0;
}
EXP10 FCFS Disk Scheduling Algorithm
#include <stdio.h>
#include <stdlib.h>
void fcfs(int arr[], int head, int size) {
int total = 0;
int i;
printf("Sequence is: ");
printf("%d -> ", head);
for (i = 0; i < size; i++) {
total += abs(head - arr[i]);
head = arr[i];
printf("%d", head);
if (i != size - 1)
printf(" -> "); }
printf("\nTotal head movement: %d\n", total);
}
int main() {
int n, head, i;
printf("Enter the number of requests: ");
scanf("%d", &n);
int requests[n];
printf("Enter 8the requests:\n");
for (i = 0; i < n; i++) {
scanf("%d", &requests[i]);
}
printf("Enter the initial position of head: ");
scanf("%d", &head);
fcfs(requests, head, n);
return 0;
}
EXPERIMENT NO- 11

AIM: A Case study on Android operating System.

PROBLEM STATEMENT: To do a Case study on Android operating System.

THEORY: The Android operating system is a mobile operating system that was developed by
Google (GOOGL) to be primarily used for touchscreen devices, cell phones, and tablets. Its
design lets users manipulate the mobile devices intuitively, with finger movements that
mirror common motions, such as pinching, swiping, and tapping.

It is free and open-source software. Its source code is Android Open-Source Project (AOSP),
primarily licensed under the Apache License. However, most Android devices dispatch with
additional proprietary software pre-installed, mainly Google Mobile Services (GMS),
including core apps such as Google Chrome, the digital distribution platform Google Play
and the associated Google Play Services development platform.

Architecture of Android OS-

The android architecture contains a different number of components to support any


android device needs. Android software contains an open-source Linux Kernel with many
C/C++ libraries exposed through application framework services.

Among all the components, Linux Kernel provides the main operating system functions to
Smartphone and Dalvik Virtual Machine (DVM) to provide a platform for running an android
application. An android operating system is a stack of software components roughly divided
into five sections and four main layers, as shown in the below architecture diagram.
Applications

Application Framework

Android

Runtime Platform Libraries Linux Kernel

Android Applications-

Android applications are usually developed in the Java language using the Android Software
Development Kit. Once developed, Android applications can be packaged easily and sold out
either through a store such as Google Play, SlideME, Opera Mobile Store, Mobango, F-droid
or the Amazon Appstore.

Android powers hundreds of millions of mobile devices in more than 190 countries around
the world. It's the largest installed base of any mobile platform and growing fast. Every day
more than 1 million new Android devices are activated worldwide.
CONCLUSION: Thus, we have studied Android Operating System.

You might also like