Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the code for two distinct C processes that are not part of a parent-child relation. These will be separate programs from separate source files.

Write the code for two distinct C processes that are not part of a parent-child relation. These will be separate programs from separate source files. They will both attach to a shared memory region containing a new type structure with four data types (first number, second-number, Sum and Flag). The first process must set the values for first and second numbers, then it updates the value of flag to 1 (which means there is new data). The second process is to find the sum of these two numbers and display the sum of the two values. It should then change the flag to zero (which means the addition was completed). The two processes will continue running this method of exchange until the first process sets the value of flag to -1 by user input.

Note that the above sample programs will continue running until the user enters a -1 value for the flag. This means that both programs will loop until the flag is set to that value. Otherwise the flag will be used to help synchronize access to the shared memory.

Hint Define the shared structure as follows: struct info { float value1, value2; float sum; int flag; }; #define KEY ((key_t)(1234)) #define MSIZ sizeof(struct info)

shmget(): int shmget(key_t key, size_t size, int shmflg); It returns the identifier of the shared memory segment associated with the value of key. Based on a value of shmflg, either a new segment is created or identifier of already created segment shmat(): void *shmat(int shmid, const void *shmaddr, int shmflg); It attaches the shared memory segment identified by shmid and returns the pointer in the calling process address space. shmctl(): int shmctl(int shmid, int cmd, struct shmid_ds *buf); It performs the control operation in the shared memory segment identified by shmid. The operation is as defined by value shmid shmdt(): int shmdt(const void *shmaddr); This function detaches the shared memory segment identified by shmaddr

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_2

Step: 3

blur-text-image_3

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

=+9. How does personal income differ from national income?

Answered: 1 week ago