Pipeline (PIPE)/createpipe

Source: Internet
Author: User
Tags readfile

Bool createpipe (phandle hreadpipe, // pointer to the read handle
Phandle hwritepipe, // pointer to the write handle
Lpsecurity_attributes lppipeattributes, // pointer to the Security Attribute
DWORD nsize // MPs queue size );

Pipe is a shared memory used for communication between processes. The process for creating an MPS queue is called the MPs Queue Server. The process connecting to an MPS queue is the MPs queue client. After a process writes data to the pipeline, another process can read data from another end of the pipeline. The anonymous pipeline (anonymous pipes) is an unnamed one-way data transmission channel between the parent process and the child process. It can only be used on a local computer and cannot be used for inter-network communication.

The MPs Queue Server sets binherithandle, a data member of the security_attributes Data Structure pointed by lppipeattributes to true. The read and write handles of the MPs queue created by createpipe () are inherited.

The parent process can call the CreateProcess () function to generate sub-processes. If the parent process needs to send data to the child process, the parent process can call writefile () to write data to the pipeline (pass the pipeline write handle to the function), and the Child process calls getstdhandle () get the read handle of the MPs queue, pass the handle into readfile (), and then read data from the MPs queue. If the parent process reads data from the child process, the child process calls getstdhandle () to obtain the write handle of the pipeline and calls writefile () to write the data to the pipeline. Then, the parent process calls readfile () to read data from the pipeline (pass the pipeline read handle to the function ).

When the writefile () function is used to write data to the pipeline, the function returns only when the specified bytes of data are written to the pipeline or when an error occurs. If the pipeline buffer is full and the data has not been written, writefile () will wait until another process reads data from the pipeline to release a lot of other available space before returning. When the MPs Queue Server calls createpipe () to create the MPs queue, it sets the buffer size of the MPs queue with the number of bytes nsize. Anonymous pipelines do not support asynchronous read and write operations, which means that readfileex () and writefileex () cannot be used in anonymous pipelines, and readfile () and writefile () the number of lpoverlapped records in will also be ignored. The anonymous pipeline closes the Read and Write handles and can also call the closehandle () function in the process to close the handles.

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.