IPC (interprocess communication)

Source: Internet
Author: User
Tags semaphore

Commonly used IPC are:

1: Pipe

2: Named Pipes (FIFO)

3: Shared storage

4: Socket

5: Semaphore

6: Message Queuing

7: Signal

pipelines only allow communication between affinity processes.

Named Pipes (FIFO) In addition to kinship processes can communicate, non-affinity processes can also communicate.

shared memory Multiple processes can access the same piece of memory space, which is the fastest IPC method. No memory copy is required to pass data between processes. Can be used between kinship and non-affinity processes.

sockets are the most common form of interprocess communication, which provides a way to communicate between processes on different machines. Message Queuing can be used between non-affinity processes

The signal Volume (semaphore) is mainly the synchronization between threads and relatives and non-affinity processes, and does not use for data transmission.

Message Queuing can be used between non-affinity processes

signals (signal) are both genetic and non-affinity processes, and can process themselves to signal themselves.

Named pipe program:

1 intMain ()2 {3 pid_t pid;4     intfd[2];5     Charline[ -];6     if(Pipe (FD) <0)7     {8printf"Pipe error\n");9     }Ten     if(PID = fork ()) <0) One     { Aprintf"Fork error\n"); -     } -     Else if(0==pid) the     { -Close (fd[1]); -Read (fd[0],line, One); -printf"%s", line); +Exit0); -     } +     Else A     { atClose (fd[0]);  -Write (fd[1],"Hello word\n", One); -     } -}

shared storage allows two or more processes to share a given storage area. This is the fastest I P C because the data does not need to be replicated between the client and the server. The only trick to using shared storage is the simultaneous (mutually exclusive) access to a given storage area between multiple processes. If the server puts the data in a shared store, the client should not fetch the data until the server has done so.

In general, semaphores (inter-unrelated processes) are used to synchronize shared storage access.

void* mmap (void * addr, size_t length, int prot, int flags, int fd, off_t offset) mmap Create a map in the process address space. It can either map a file to memory, or map a piece of memory to enable inter-process memory sharing.

Once a shared bucket is created, the process can call Shmat to connect it to its address space

IPC (interprocess communication)

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.