experimental purposes
Learn more about the steps to use shared memory by writing a shared memory experiment, while deepening your understanding of shared memory. In this experiment, the signal quantity is used as the synchronization mechanism to perfect the communication between the two processes ("producer" and "consumer").
Experimental Content
Use shared memory to enable file opening and read-write operations. Required Knowledge points: signal volume, shared memory.
Experiment Flow Chart
Experimental Code
This experiment altogether needs 5 files, in which Producer.c realizes the function of the producer, Customer.c realizes the function of the consumer, the other shm_com.h, SEM_COM.C, sem_ Com.h is a modular file that is called by producer.c and customer.c files. The experimental structure diagram is as follows
The 5 files, I have uploaded to the resources, if necessary, please download, click here to download
Producer.c
Customer.c
Execution Procedure
After the 5 files have been written, they are compiled using the command
GCC producer.c sem_com.c-o producer
GCC customer.c sem_com.c-o Customer
Perform producer at Terminal 1
Perform customer in Terminal 2
Enter the characters in Terminal 1 and the results are as follows