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:
- Initialize an integer x with 19530
- Create a child process
- Decrease the variable x by 5
- Send the value of x to the child process
- The child process will
- Divide x by 5
- 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.
- 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.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started