Question: Do it in LINUX ONLY ) Implement a process (C program) to do the following: (a) initialize an integer x with 19530 (b) create a

Do it in LINUX ONLY

) Implement a process (C program) to do the following:

(a) initialize an integer x with 19530

(b) create a child process

(c) decrease the variable x by 5

(d) send the value of x value to the child process

(e) the child process will

i. divide x by 5

ii. pass the updated value of x back to the parent process

Code for above instruction is

#include

#include

#include

#include

int main(void)

{

int x,i;

int status;

int parent_id,parent_id1,parent_id2,parent_id3,parent_id4,parent_id5;

x=19530;

parent_id=fork();

if (parent_id==0)

{

printf("x = %d ",x);

exit(EXIT_SUCCESS);

}

else

{

x=x-5;

wait(&status);

}

parent_id1=fork();

if (parent_id1 == 0)

{

printf ("ITERATION 1 ");

printf ("Parent : x = %d ",x);

x=x/5;

printf ("Child : x = %d ",x);

exit(EXIT_SUCCESS);

}

else

{

x=x/5;

x=x-5;

wait(&status);

}

parent_id2=fork();

if (parent_id2 == 0)

{

printf ("ITERATION 2 ");

printf ("Parent : x = %d ",x);

x=x/5;

printf ("Child : x = %d ",x);

exit(EXIT_SUCCESS);

}

else

{

x=x/5;

x=x-5;

wait(&status);

}

parent_id3=fork();

if (parent_id3 == 0)

{

printf ("ITERATION 3 ");

printf ("Parent : x = %d ",x);

x=x/5;

printf ("Child : x = %d ",x);

exit(EXIT_SUCCESS);

}

else

{

x=x/5;

x=x-5;

wait(&status);

}

parent_id4=fork();

if (parent_id4 == 0)

{

printf ("ITERATION 4 ");

printf ("Parent : x = %d ",x);

x=x/5;

printf ("Child : x = %d ",x);

exit(EXIT_SUCCESS);

}

else

{

x=x/5;

x=x-5;

wait(&status);

}

parent_id5=fork();

if (parent_id5 == 0)

{

printf ("ITERATION 5 ");

printf ("Parent : x = %d ",x);

x=x/5;

printf ("Child : x = %d ",x);

exit(EXIT_SUCCESS);

}

else

{

x=x/5;

x=x-5;

wait(&status);

}

printf("Finished with all the processes. ");

exit(EXIT_SUCCESS);

return 0;

}

Redo ^above code, but this time only using the signal mechanism system call (don't use wait() or pipe(), you may still need sleep()). You can still write or read to disk.

Output should look like

Do it in LINUX ONLY ) Implement a process (C program) to

Thank You :)

X-19530 ITERATION 1 Parent : x 19525 Child : x = 3905 TERATION 2 Parent : x = 3900 Child : x 780 TERATION 3 Parent : x 775 Child : x= 155 ITERATION 4 Parent x-150 Child : x = 30 ITERATION 5 Parent x-25 Child : x = 5 X-19530 ITERATION 1 Parent : x 19525 Child : x = 3905 TERATION 2 Parent : x = 3900 Child : x 780 TERATION 3 Parent : x 775 Child : x= 155 ITERATION 4 Parent x-150 Child : x = 30 ITERATION 5 Parent x-25 Child : x = 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!