Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a FIFO file type in Linux

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to create a FIFO file type in Linux, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

FIFO, also known as named pipe (named pipe), is a method for interprocess communication in Linux systems.

The difference between FIFO and pipe is:

FIFO has a corresponding inode in the file system, which can be viewed through the ls command.

Sh-3.2# ls-lhF. / fifo_file

100 prwxrwxrwx 1 root root 0 Jan 1 1970 . / fifo_file |

Sh-3.2#

Because it has a name, any process can access it, so FIFO can be used for communication between any two processes.

Pipe does not have a name and its existence cannot be seen in the existing file system.

It can only be used for inter-process communication such as father-son process, sibling process and so on.

The method to create FIFO is as follows:

1. Call umask system call to set the permission to create a file

# include "sys/types.h"

# include "sys/stat/h"

Mode_t umask (mode_t mask)

two。 Delete the existing fifo first by calling the unlink system call

# include "unistd.h"

Int unlink (const char * pathname)

3. Call the mkfifo library function to create a FIFO file

# include "sys/types.h"

# include "sys/stat.h"

Int mkfifo (const char * pathname, mode_t mode)

Or you can create a FIFO file by calling mknod system call and specifying the parameter mode as S_IFIFO

# include "sys/types.h"

# include "sys/stat.h"

# include "fcntl.h"

# include "unistd.h"

Int mknod (const char * pathname, mode_t mode, dev_t dev)

Note:

1. Use FIFO for communication, and the data transferred each time should be limited to PIPE_BUF.

two。 Access to FIFO is like accessing a regular file (regular file), which can be accessed using system calls such as open/read/write/close.

Applications that use FIFO include:

1. Pure producer / consumer problem, one process reads data, one process writes data

two。 To achieve the client/server architecture of the program, the client and server-side communication through FIFO.

On how to create a FIFO file type in Linux to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report