Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Fork and wait system calls required . Program should also create a file to store variable x in so that the parent/child processes can share
Fork and wait system calls required. Program should also create a file to store variable x in so that the parent/child processes can share the information.
Task 1 (100 points) Implement a program that will communicate the value of an integer x, between processes. You can do this using a file to store the value of x, or you can use shared memory with shmget or mmap. Shared memory is out of the scope of this class, so you will have to teach yourself how to use it, however if you put in the effort to learn, it results in simpler more elegant code. x will start with the value 19530, and you must print that value. Then you will loop 5 times where in each loop: the child goes first and subtracts 5 from x, the parent then divides x by 5, and both processes print who they are and their result of x after the operation. If you use a file and not shared memory, then during each iteration of the loop both processes must get the value of x from the file, and store the resulting value of x to the file. wait0 is a required function call, so you will need to create a new process, and terminate it each time through the loop The following system calls are required for this lab: fork) waitO The following functions may be useful for this lab: * open), read), write) Sleep() : make the process wait for a number of seconds . atoi): converts string to integer Task 1 (100 points) Implement a program that will communicate the value of an integer x, between processes. You can do this using a file to store the value of x, or you can use shared memory with shmget or mmap. Shared memory is out of the scope of this class, so you will have to teach yourself how to use it, however if you put in the effort to learn, it results in simpler more elegant code. x will start with the value 19530, and you must print that value. Then you will loop 5 times where in each loop: the child goes first and subtracts 5 from x, the parent then divides x by 5, and both processes print who they are and their result of x after the operation. If you use a file and not shared memory, then during each iteration of the loop both processes must get the value of x from the file, and store the resulting value of x to the file. wait0 is a required function call, so you will need to create a new process, and terminate it each time through the loop The following system calls are required for this lab: fork) waitO The following functions may be useful for this lab: * open), read), write) Sleep() : make the process wait for a number of seconds . atoi): converts string to integerStep 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