Performa Lab-2
Performa Lab-2
on
Pardeep Singh for his patience, support and encouragement throughout the
At last but not the least I greatly indebted to all other persons who
Ayush Maheshwari
Session: 2021-22
GEHU, Dehradun
DEPARTMENT OF CSE
STUDENT LAB REPORT
SHEET Photograph
Passport Size
Name of Student ……………………………………….…….Mob.No……………………………….…………..
9
10
11
PROGRAM-1
SOURCE CODE:
#include <stdio.h>
#include <unistd.h>
int main() {
printf("working of fork() function\n");
fork();
return 0;
}
OUTPUT:
PROGRAM-2
SOURCE CODE:
#include <stdio.h>
#include <unistd.h>
int main() {
int n, oddsum = 0, evensum = 0;
int arr[n];
int x = fork();
if (x == 0) {
for (int i = 0; i < n; i++) {
if (arr[i] % 2 == 0) {
evensum = evensum + arr[i];
}
}
printf("sum of even numbers: %d, calculated by child process with process ID %d\n", evensum,
getpid());
}
else {
for (int i = 0; i < n; i++) {
if (arr[i] % 2 != 0) {
oddsum = oddsum + arr[i];
}
}
printf("\nsum of odd numbers: %d, calculated by parent process with process ID %d\n", oddsum,
getpid());
}
return 0;
}
OUTPUT:
PROGRAM-3
SOURCE CODE:
ZOMBIE PROCESS:
#include <stdio.h>
#include <unistd.h>
int main() {
int x = fork();
if (x == 0) {
printf("\nchild process executing with process id:%d\n", getpid());
printf("\nchild process is finished\n");
} else {
sleep(10);
printf("\nparent process executing with process id:%d\n", getpid());
printf("\nparent process is finished\n");
}
return 0;
}
ORPHAN PROCESS:
#include <stdio.h>
#include <unistd.h>
int main() {
int x = fork();
if (x == 0) {
sleep(5);
printf("\nchild process is executing with process ID %d\n", getpid());
printf("\nchild process is finished\n");
} else {
printf("\nparent process is executing with process ID %d\n", getpid());
printf("\nparent process is finished\n");
}
return 0;
}
OUTPUT:
ZOMBIE:
ORPHAN:
PROGRAM-4
SOURCE CODE:
#include <stdio.h>
struct Process {
int process_id;
int arrival_time;
int burst_time;
};
processes[j + 1] = temp;
}
void calculateCompletionTime(struct Process processes[], int n, int completion_time[]) {
} else {
int completion_time[n];
int turnaround_time[n];
int waiting_time[n];
calculateCompletionTime(processes, n, completion_time);
int total_cpu_time = 0;
for (int i = 0; i < n; i++) {
avg_waiting_time += waiting_time[i];
avg_turnaround_time += turnaround_time[i];
total_cpu_time += processes[i].burst_time;
avg_waiting_time /= n;
avg_turnaround_time /= n;
printf("Process\t Arrival Time\t Burst Time\t Completion Time\t Turnaround Time\t Waiting Time\
n");
int main() {
int n;
scanf("%d", &n);
processes[i].process_id = i + 1;
scanf("%d", &processes[i].arrival_time);
scanf("%d", &processes[i].burst_time);
}
sortProcessesByArrivalTime(processes, n);
calculateAverageTime(processes, n);
return 0;
}
OUTPUT: