Question: Implement a process (C program) to do the following: Initialize an integer x with 19530 Create a child process Decrease the variable x by 5

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

  1. Initialize an integer x with 19530
  2. Create a child process
  3. Decrease the variable x by 5
  4. Send the value of x to the child process
  5. The child process will
  1. Divide x by 5
  2. Pass the updated value of x back to the parent process

Steps 3 to 5 should be repeated 5 times printing out the iteration number, and each process should print out the value of x every time it changes it.

Key system calls to be used are: fork(),open(), write(), read(), lseek(), and the only standard library function to be used is printf().

Two processes can communicate using a file as a message container. Specifically, writing and reading x to/from the same file, which would make the (output) file look like the following sample.

  1. 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 the disk.
  2. You should have one parent process and one child process only.

Your output should look like

x = 19530

ITERATION 1

Parent : x = 19525

Child : x = 3905

ITERATION 2

Parent : x = 3900

Child : x = 780

ITERATION 3

Parent : x = 775

Child : x = 155

ITERATION 4

Parent : x = 150

Child : x = 30

ITERATION 5

Parent : x = 25

Child : x = 5

plz make in C++ or c and show with pictures.

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!