A well-known pipeline of interprocess communication

Source: Internet
Author: User

Process communication is the exchange of information between processes (transferring data). The current computer system provides a multitasking parallel environment that requires the creation of processes for each task, whether it be an application or a system program.

Each process is independent of each other, and different processes run in their own different memory spaces, so information transfer between processes cannot be done directly through variables or other data structures, but only through interprocess communication.

inter-process communication mode: Signal , pipelines, semaphores, message queues, shared memory, Socket

Today, we introduce the communication between programs through pipelines. Pipelines are divided into famous pipes and nameless pipes.

(pipe file) (Half-duplex communication: Data flow is unidirectional.) )

Well- known pipeline: There is a file identifier (file name) in the file system, but the pipe file does not occupy disk space and the data that needs to be passed is cached in the memory area. Can be used to run any of the two processes in a system. (with attribute information,inode node exists on disk)

Nameless pipe: Used for communication between parent and child processes. No attribute information, no inode nodes.

before we could get data from each other through files. (Put data on disk) get through I/O (slow)

Pipeline File Creation: (command)mkfifo file name

(function) Int Mkfifo(const char *pathname ,mode_t mode)

The first parameter is going to create a private file in the file system, and the second parameter specifies FIFO Read and Write permissions.

cannot create a pipe file with open

Operation of pipeline files:

Open : int Open (char *path, int flag)

read: int read (int fd, void *buff,size_t size)

write: int write (int fd, void *buff, size_t size)

Close :int Close (int fd)

1. Open opens a pipe file with read-only, and The Open will block until a process opens the pipeline file with write-only or read-write.

2 . open to write-only opens a pipeline file, Open will block the run until a process opens the pipeline file with read-only or read-write.

3 . The read function also blocks the run until there is data or shutdown in the pipeline.

4, write function will also block the run, when writing too much is written to block the operation to wait until the data read to go on to write.

A well-known pipeline of 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.