Linux interprocess communication (10)---Shared memory experiment of integrated experiment __linux

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.