Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a copy of called childcreates.c. Modify the C program so that each proces

ID: 3603468 • Letter: C

Question

Create a copy of called childcreates.c. Modify the C program so that each process creates exactly one a new process. Keep the printf call for all processes. The resulting diagram will look something like the following when childcreates 3 is called: 414 -> 416 -> 417 -> 420.

Note : Before modifing, if we run childcreates 1, two processes are created, the original parent process and its child. Assuming the process id of the parent is 414 and the process id of the child is 416, we can represent the relationship between these processes using the following ASCII diagram: 414 -> 416

parentcreates.c 2 3 4 #include #include«unistd.h> #include«stdlib.h> 5 int main(int argc, char kargv) f int i; int iterations; if (argc != 2) { 9 10 fprintf (stderr, "Usage: forkloop "); exit(1); 12 13 14 15 16 17 18 19 20 21 iterations = strtol (argv [1], NULL, 10); for (i= 0; i

Explanation / Answer

#include <fcntl.h>
char buffer! 2048];

int version - 1; /* Chapter 2 explains this */


main(argc, argv)
int argc;
char *argv[];

{

int fdold, fdnew;
if (argc !— 3)

printf ("need 2 arguments for copy program '’);
exit(l);

fdold - open(argvtlI, O RDONLY); /* open source file read only */

if (fdold 1)

(

printf ("cannot open file %s ", argvlll);
exit(l);

fdnew - creat(argv[2], 0666); /* create target file rw for all */

if (fdnew -»* —1)

{

printf ("cannot create file %s ", argv[2j);
exit(l);

}

copy (fdold, fdnew);
exit(0);

}


copy(old, new)

int old, new;

{


int count;


}


while ((count * read (old, buffer, sizeof(buffer))) > 0)
write(new, buffer, count);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote