Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Unix, show output Example code to help continue: #include #include #include #include #include #include int readValue(); void writeValue(int i); int main () { int i

Unix, show output

image text in transcribed

image text in transcribed

Example code to help continue:

#include #include #include #include #include #include

int readValue(); void writeValue(int i);

int main () { int i = 5432; char buffer[10];

int fd = open("number.dat", O_CREAT | O_TRUNC | O_WRONLY); int byteNum = sprintf(buffer, "%d", i);

write(fd, buffer, byteNum);

close (fd);

int j; char buffer2[10]; int fd2 = open("number.dat", O_RDONLY); read(fd2, buffer2, 10); j = atoi(buffer2); close(fd2);

printf("number read: %d ", j);

return 0;

}

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 rill have to teach yourself how to use it, however if you put in the effort to leari, 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 opcration. 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. wait() 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() wait lhe 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 sprintf ca be used to convert integer to string fflush(): forces a file buffer to flush. This is useful to flush stdout before creating a child so you don't have two processes printing the same buffer to the screen. This can sometimes fix strange printing bchavior The following is an example of what you will output to the screen

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

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

=+derived from the assignment will balance the costs?

Answered: 1 week ago

Question

=+6 Who is the peer of the IA ?

Answered: 1 week ago