OS 3rd experiment report: named pipes

  • Name: Wu Yanzhen
  • Student ID: 201821121034
  • Class: Calculate 1812

1. Write a program

Vim write programs on the server: Create a named pipe, two processes are created for the pipeline to read fifo_read.cand write fifo_write.c. (Given the source code)

(1) Read the fifo_read.c program, the source code is as follows:

 

(2) Write the fifo_write.c program, the source code is as follows:

 

2. Analyze the operation results

(1) Operation result:

(2) Analysis:

  Open two terminals and run the read and write programs simultaneously. Cyclic input of content, the content can be read out sequentially through the reading program

  mkfifo () function:

int mkfifo(const char *filename,mode_t mode)

  · The required header files are: #include <sys / types.h> #include <sys / stat.h>

  ·mode:

    O_RDONLY: read pipeline

    O_WRONLY: write pipeline

    O_RDWR: read and write pipeline

    O_NONBLOCK: non-blocking

  · If the function is successfully executed, the return value is 0, otherwise it is -1

3. Generate new questions and answers through this experiment

Question: Congestion issues related to pipeline reading and writing

Answer: O_NONBLOCK in the open () function, indicating a non-blocking flag

  • For the reading process: when the pipeline is blocked, if there is no data in the FIFO, the process will block until data is written; when the pipeline is not blocked, the reading process will be executed immediately, if the FIFO has no data, the function will return 0
  • For the write process: in the case of a blocked pipeline, the write operation will block until the data can be written; in the case of the pipeline is not blocked but cannot write all the data, the read operation partially writes or the call fails

Guess you like

Origin www.cnblogs.com/will-h/p/12708439.html