OS ALL output
OS ALL output
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];
}
if (a != -1) {
process = a + 1;
goto A;
}
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.
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
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.