How Linux creates a FIFO file type

Source: Internet
Author: User
Tags file system

FIFO pipeline is a file type, the creation of FIFO on Linux is very easy, FIFO file inherent pipe characteristics, but and pipe pipeline has a certain difference, the following small series will be for the FIFO pipeline creation and use to do a detailed introduction, so that you have a detailed understanding.

FIFO, also known as a named pipe (named pipe), is a way to communicate between processes in a Linux system.

  The difference between FIFO and pipe is:

FIFO in the file system has the corresponding inode, can be viewed through the LS command.

sh-3.2# LS-LHF. /fifo_file

1 root root 0 prwxrwxrwx 1 1970. /fifo_file|

sh-3.2#

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

Pipe has no name and cannot see it in the existing file system.

It can only be used for inter process communication between parent-child process, sibling process, etc.

  The FIFO method is created as follows:

1. Call the Umask system call to set the permissions to create the file.

#include "Sys/types.h"

#include "sys/stat/h"

mode_t umask (mode_t mask);

2. Call the unlink system call to first delete the existing FIFO,

#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);

Alternatively, you can create a FIFO file by calling the Mknod system call and specifying parameter mode for 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);

  Attention:

1. Use FIFO for communication, each transmission of data to be limited within pipe_buf;

2. For FIFO access, as with access to regular files (regular file), you can access them using system calls such as Open/read/write/close.

  The use of FIFO applications are:

1. Simple producer/consumer issues, a process reading data, a process writing data;

2. Implementation of the Client/server framework of the program, client and server-side through FIFO communication.

Above is the Linux to create FIFO pipeline introduction, this article in addition to the introduction of FIFO pipeline creation, but also a little introduction to the use of the next FIFO and considerations, in the use of time to pay special attention.

Related Article

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.