OneCompiler

OS7

96

#include <stdio.h>
#include <unistd.h>
int main() {
pid_t child_pid = fork();
if (child_pid == 0) {
execl("/bin/ls", "ls", (char *)NULL);
} else if (child_pid > 0) {
sleep(5);
} else {
perror("Fork failed");
return 1;}
return 0;

#2
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int n; srand(time(NULL));
printf("Enter the number of processes: "); scanf("%d", &n);
float tTAT = 0, tWT = 0, t = 0;
for (int i = 0; i < n; i++) {
int burst = rand() % 10 + 1;
t += burst + 2;
printf("P%d %d %d\n", i + 1, (int)t, (int)t - burst);
tTAT += t;
tWT += t - burst;}
printf("Avg TAT: %.2f\nAvg WT: %.2f\n", tTAT / n, tWT / n);
return 0