Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Question

Solve Vu=0, 0

Answered: 1 week ago