Write two simple C programs that communicate with each other via shared memory.
ID: 3559010 • Letter: W
Question
Write two simple C programs that communicate
with each other via shared memory. The first program receiver.c runs in an
infinite loop receiving alpha numeric strings as input from the user one line
at a time. After reading one line from the standard input, this program sends
this information to the other program. The sharing of data between the two
processes should take place via shared memory. The second program processor.c
creates an output file vowels.out and waits for user input to be sent by the
receiver program. As soon as one line is received from the receiver, it counts
the number of vowels in that line and dumps the vowel count along with the
original line in the vowels.out file. This program also runs in an infinite
loop.
Explanation / Answer
We develop two programs here that illustrate the passing of a simple piece of memery (a string) between the processes if running simulatenously:
shm_server.c
-- simply creates the string and shared memory portion.
shm_client.c
-- attaches itself to the created shared memory portion and uses the string (printf.
The code listings of the 2 programs no follow:
shm_server.c
shm_client.c
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.