pthreads (1)
pthreads (1)
pthreads (1)
h>
struct Process {
int pid;
int arrival_time;
int burst_time;
int waiting_time;
int turnaround_time;
};
int main() {
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);
fcfs_scheduling(processes, n);
return 0;}
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
return 0;
}
close(sfd);
close(dfd);
}
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("\nKernel Version:\n");
system("cat /proc/version");
printf("\nInformation on Configured amount of free and used memory\n");
system("cat /proc/meminfo | awk '/Mem/ {print}'");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Kernel Version:\n");
system("cat /proc/version");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
#include<sys/types.h>
void sameprogramsamecode(){
system("clear");
fprintf(stdout,"Now parent and child will execute same code print pid of themselves
and then exit\n");
fprintf(stdout,"pid: %d\n", getpid());
exit(1);
}
void sameprogramdifferentcode(){
fprintf(stdout,"Now we will execute different code in parent and child\n");
pid_t pid = fork();
if(pid == 0){
fprintf(stdout,"Inside child with pid: %d\n", getpid());
exit(1);
} else if(pid > 0){
fprintf(stdout,"Inside parent with pid: %d\n", getpid());
} else {
fprintf(stderr,"ERROR: while forking");
}
}
void sameprogramwaitforchildtoexit(){
fprintf(stdout,"Now we will execute different code in parent and child and parent
will wait for child\n");
pid_t pid = fork();
if(pid == 0){
fprintf(stdout,"Inside child with pid: %d\n", getpid());
fprintf(stdout,"Exiting child\n");
exit(1);
} else if(pid > 0){
sleep(1);
fprintf(stdout,"Inside parent with pid: %d\n", getpid());
fprintf(stdout,"Parent waiting for child\n");
wait(NULL);
fprintf(stdout,"Exiting parent\n");
} else {
fprintf(stderr,"ERROR: while forking");
exit(1);
}
}
int main(){
int choice;
while(1){
printf("1) Same program and same code\n");
printf("2) Same program and different code\n");
printf("3) Before terminating the parent wait for the child to finish its task\n");
printf("4) Enter 0 to exit\n");
scanf("%d", &choice);
switch(choice){
case 0:
exit(0);
case 1:
sameprogramsamecode();
break;
case 2:
sameprogramdifferentcode();
break;
case 3:
sameprogramwaitforchildtoexit();
break;
default:
printf("ERROR: wrong choice try again...\n");
}
}
return 0;
}