LINUX study note 12-inter-process communication 1 Pipeline

Source: Internet
Author: User

1. Overview:
 
A) why inter-process communication: data transmission, resource sharing, notification events, and process control;
 
B) basic source:
 
1. UNIX Process Communication:
 
2. inter-process communication based on system v:
 
A) system v: a branch of the UNIX operating system interface
 
3. Posix inter-process communication:
 
A) Posix: port operating system interfaces
 
C) classification: pipelines; SIGNALS; message queues; shared memory; semaphores; sockets
 
2. Pipeline communication:
 
A) features:
 
1. One-way, first-in-first-out
 
2. Write: at the end of the MPs queue
 
3. Read: in the pipeline's header
 
B) Category:
 
1. Unknown pipeline: used for communication between parent and child Processes
 
2. Famous pipe: used for communication between any two processes
 
C) unknown pipeline:
 
1. Create a pipe: Int pipe (int filedis [2]);
 
A) Filedis [0]: used to read the media transcoding queue, file descriptor, and generate the media transcoding queue after the media transcoding queue is created.
 
B) Filedis [1]: used for writing Pipelines
 
C) Return Value: Success is 0, failure is-1
 
D) # include <unistd. h>
 
2. close the pipeline: close (filedis [0]); close (filedis [1]);
 
3. Note:
 
A) pipe () must be called before fork (). Otherwise, the sub-process will not inherit the file descriptor.
 
B) after creating a sub-process, you must disable unused ports.
 
C) in order to be able to read and write normally, the read process needs to wait for a while so that the write process can write data for a while.
 
4. write pipeline: write (filedis [1], "string", sizeof (s ));
 
5. read pipeline: read (filedes [0], buffer, 80 );
 
A) store the data in the buffer array. 80 is the length of the buffer.
 
D) famous pipelines:
 
1. essence: a file
 
2. Create a pipe: Int mkfifo (const char * pathname, mode_t mode );
 
A) If (mkfifo (pathname, O_CREAT | O_EXCL) <0) & (errno! = EEXIST ))
 
B) pathname: File Name
 
C) mode: File Permission. Once created, file programming is available.
 
D) Return Value: Success is 0, failure is-1
 
E) # include <sys/types. h>
 
# Include <sys/stat. h>
 
3. close the file: unlink (const char * pathname );
 
4. open the file: Int open (const char * pathname, int flags, [mode])
 
A) Fd = open (pathname, O_RDONLY | O_NONBLOCK)
 
B) Pathname: the complete path is required.
 
C) non-blocking MARK: O_NONBLOCK
 
1. Not used: the process will be blocked when the access fails to meet the requirements.
 
2. Use: When the access fails to meet the requirements, the process is not blocked and an error is returned immediately. errno is ENXIO.
 
5. write pipeline: write (fd, "string", sizeof (s ));
 
6. read pipeline: read (fd, buffer, 80 );
 
A) store the data in the buffer array. 80 is the length of the buffer.
 
B) Remember to clear the memset (buffer, 0, 80) in the buffer before each data read, # include <string. h>
 
C) Buffer should be in the string format
 
7. Note:
 
A) the data in the pipeline is read once.
 
B) the MPs queue is generally created and closed by the Data Reading Process.

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.