Linux interprocess communication (IPC)

Source: Internet
Author: User

Linux interprocess communication (IPC)
Description: First of all, I would like to write a few words to be asked in the interview at the time of the detailed1, why should there be interprocess communication? parsing: Because interprocess communication is mainly about exchanging data between different processes, and the exchange of data must be implemented by the kernel , the global variables of any process are invisible in another process, so the kernel opens up a buffer, Process a puts data into the kernel, and process B takes the data away from the kernel, enabling interprocess communication2. How many communication methods are there between interprocess communication? resolution: Pipe, FIFO, System V Message Queuing, System V Semaphore, System V shared memory3. How many kinds of communication are introduced? Parse: Pipe (pipe): Use pipe (int filedes[2]) to create the pipeline, the created pipeline has a read and write end, can only be used for the relationship between interprocess communication, one-way communication, byte-based throttling. FIFO (named pipe): overcomes the inter-pipeline communication between the relationships, it is to create a real file, and then write to the file, read to the file read data, always FIFO, with int mkfifo (const char *filename, mode_t mode), int mknod (const char *filename,mode_t mode | S_ififo, (dev_t) 0); The created pipeline can communicate with any interprocessThe most important three interprocess communication comes in: (1) System V Message Queuing: It is message-based Message Queuing, is also the creation of read and write terminals respectively, can be used for any interprocess communication, requires three functions to implement, int msgget (key_t key,int msgflg): Create a message queue or get an existing message queue, int msgrcv (int msgqid,void *msgp,size_t msgzs,long msgtype,int msgflg): Take a message from the queue, int msgsnd (int msgid, Const void*msgp,size_t Msgzs,int MSGFLG): Put data into message queue, int msgctl (int msgqid,int cmd,struct msgqid_ds *buf): Set Message Queuing properties(2) System V Semaphore: The semaphore itself does not have the ability to make data communication, it is equivalent to a lock, it is only an external resource identification, with the signal to achieve the process of mutual exclusion and synchronization, mainly by SEMGET,SEMOP,SEMCTL to achieve process communication, is equivalent to the P, v operation in the mutex(3) System V Shared Memory: Shared memory is the fastest communication in all IPC, because it creates a buffer in memory, all processes can be accessed by this buffer, it is fast mainly to access the data only two copies can be completed, While other inter-process communication requires four copies to complete the communication, it also has a fatal disadvantage in multi-process or multi-threaded thread security, all shared memory communication is generally with the semaphore or mutex, condition variable set used to ensure the data in the communication time consistencyPS:Message Queuing, semaphores, shared memory all have System V and POSIX points, there are some differences between them, the latter will be mended

Linux interprocess communication (IPC)

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.