Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone to expalin me this code ? #include #include #include #include #include int main ( ) { FILE * filename = fopen (

can someone to expalin me this code ? #include
#include
#include
#include
#include
int main(){
FILE *filename = fopen ("writeToFile.dat", "w");
if (fork ()==0){
for (int i =0; i <3; i++){
printf ("First child P1
");
fprintf (f, "First child P1
");
}
}
else if (fork ()==0){
for (int i =0; i <2; i++){
printf ("Second child P2
");
fprintf (f, "Second child P2
");
}
}
else if (fork ()==0){
printf ("Third child P3
");
fprintf (f, "Third child P3
");
}
else {// Parent
wait (NULL); // wait for one child to finish
wait (NULL); // wait for another child to finish
wait (NULL); // wait for last child to finish
fclose (f);
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions