Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a code that in C that Uses the system service calls shmget and shmat to obtain some new memory that will be accessible to

Write a code that in C that Uses the system service calls shmget and shmat to obtain some new memory that will be accessible to multiple processes (and use shmdt and shmctl to clean up when you're done).

1) First use shmget to tell the OS to assign you a segment of memory (to be shared among multiple processes) big enough to hold an integer; have your program print out the shared memory identifier it receives from shmget.

Next, use shmat to get the address for your process to use to refer to the shared memory (this step is known as "attaching" the shared memory to your process).

2) The parent process should set the new (shareable) integer to 0 and then spawn a child process

3) In the parent (after the spawn):

Ask the user for a (non-zero) value to store in the new integer.

Once that has been accomplished, the parent should spin on that integer until it becomes zero again.

After exiting from the spin, the parent should print a message saying that the shared integer is now 0 again (thus confirming successful two way communications via shared memory).

Detach the shared memory from the process's address space using shmdt

Return the shared memory segment to the memory manager using shmctl (roughly analogous to the "free" function used to return malloc'd memory).

Print out an "all done" message.

4) In the child (after the spawn):

Print some sort of "I'm here" message

Spin on the new integer until it becomes non-zero.

After exiting from the spin (because the parent eventually puts a user-supplied non-zero value in the shared integer), print out the value just received from its parent and then re-set the shared integer back to 0 (so the parent can eventually stop spinning and finish up).

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago