linux C语言mkfifo()函数 mkfifoat()函数(制作一个 FIFO 特殊文件(命名管道))
Posted Dontla
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux C语言mkfifo()函数 mkfifoat()函数(制作一个 FIFO 特殊文件(命名管道))相关的知识,希望对你有一定的参考价值。
文章目录
man 3 mkfifo
MKFIFO(3) Linux Programmer's Manual MKFIFO(3)
NAME
mkfifo, mkfifoat - make a FIFO special file (a named pipe)
//制作一个 FIFO 特殊文件(命名管道)
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
int mkfifo(const char *pathname, mode_t mode);
#include <fcntl.h> /* Definition of AT_* constants */
#include <sys/stat.h>
int mkfifoat(int dirfd, const char *pathname, mode_t mode);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
mkfifoat():
Since glibc 2.10:
_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
Before glibc 2.10:
_ATFILE_SOURCE
DESCRIPTION
mkfifo() makes a FIFO special file with name pathname. mode specifies the FIFO's permissions. It is modified by the process's umask in the usual way: the
permissions of the created file are (mode & ~umask).
//mkfifo() 创建一个名为 pathname 的 FIFO 特殊文件。
//mode 指定 FIFO 的权限。 它由进程的umask以通常的方式修改:创建文件的权限为(mode & ~umask)。
A FIFO special file is similar to a pipe, except that it is created in a different way. Instead of being an anonymous communications channel, a FIFO spe‐
cial file is entered into the filesystem by calling mkfifo().
//FIFO 特殊文件类似于管道,只是它的创建方式不同。
//不是匿名通信通道,而是通过调用 mkfifo() 将一个 FIFO 特殊文件输入到文件系统中。
Once you have created a FIFO special file in this way, any process can open it for reading or writing, in the same way as an ordinary file. However, it
has to be open at both ends simultaneously before you can proceed to do any input or output operations on it. Opening a FIFO for reading normally blocks
until some other process opens the same FIFO for writing, and vice versa. See fifo(7) for nonblocking handling of FIFO special files.
//一旦你以这种方式创建了一个 FIFO 特殊文件,任何进程都可以打开它进行读取或写入,就像普通文件一样。
//但是,它必须同时在两端打开,然后才能继续对其进行任何输入或输出操作。
//打开一个 FIFO 进行读取通常会阻塞,直到某个其他进程打开同一个 FIFO 进行写入,反之亦然。
//有关 FIFO 特殊文件的非阻塞处理,请参见 fifo(7)。
mkfifoat()
The mkfifoat() function operates in exactly the same way as mkfifo(), except for the differences described here.
//mkfifoat() 函数的操作方式与 mkfifo() 完全相同,除了此处描述的不同之处。
If the pathname given in pathname is relative, then it is interpreted relative to the directory referred to by the file descriptor dirfd (rather than rela‐
tive to the current working directory of the calling process, as is done by mkfifo() for a relative pathname).
//如果 pathname 中给出的路径名是相对的,那么它被解释为相对于文件描述符 dirfd 所引用的目录(就是说dirfd是一个打开的文件的文件标识符,后面的pathname相对路径是相对于这个文件标识符所指向的文件的)
//(而不是相对于调用进程的当前工作目录,如 mkfifo() 对相对路径名所做的那样)。
If pathname is relative and dirfd is the special value AT_FDCWD, then pathname is interpreted relative to the current working directory of the calling
process (like mkfifo()).
//如果路径名是相对的并且 dirfd 是特殊值 AT_FDCWD,
//则路径名被解释为相对于调用进程的当前工作目录(如 mkfifo())。
If pathname is absolute, then dirfd is ignored.
//如果路径名是绝对的,则忽略 dirfd。
RETURN VALUE
On success mkfifo() and mkfifoat() return 0. In the case of an error, -1 is returned (in which case, errno is set appropriately).
//成功时 mkfifo() 和 mkfifoat() 返回 0。
//如果出现错误,则返回 -1(在这种情况下,errno 已适当设置)。
ERRORS
EACCES One of the directories in pathname did not allow search (execute) permission.
//路径名中的目录之一不允许搜索(执行)权限。
EDQUOT The user's quota of disk blocks or inodes on the filesystem has been exhausted.
//文件系统上用户的磁盘块或 inode 配额已用完。
EEXIST pathname already exists. This includes the case where pathname is a symbolic link, dangling or not.
//路径名已经存在。 这包括路径名是符号链接的情况,无论是否是死链接。
ENAMETOOLONG
Either the total length of pathname is greater than PATH_MAX, or an individual filename component has a length greater than NAME_MAX. In the GNU
system, there is no imposed limit on overall filename length, but some filesystems may place limits on the length of a component.
//路径名的总长度大于 PATH_MAX,或者单个文件名组件的长度大于 NAME_MAX。
//在 GNU 系统中,对文件名的总长度没有强加限制,但某些文件系统可能会限制组件的长度。
ENOENT A directory component in pathname does not exist or is a dangling symbolic link.
//路径名中的目录组件不存在或者是死链接。
ENOSPC The directory or filesystem has no room for the new file.
//目录或文件系统没有空间容纳新文件。
ENOTDIR
A component used as a directory in pathname is not, in fact, a directory.
//在pathname中用作目录的组件实际上不是目录。
EROFS pathname refers to a read-only filesystem.
//pathname 指的是只读文件系统。
The following additional errors can occur for mkfifoat():
//mkfifoat() 可能会出现以下附加错误:
EBADF dirfd is not a valid file descriptor.
//dirfd 不是有效的文件描述符。
ENOTDIR
pathname is a relative path and dirfd is a file descriptor referring to a file other than a directory.
//pathname 是一个相对路径,dirfd 是一个文件描述符,它指的是一个文件而不是目录。
VERSIONS
mkfifoat() was added to glibc in version 2.4. It is implemented using mknodat(2), available on Linux since kernel 2.6.16.
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).
┌─────────────────────┬───────────────┬─────────┐
│Interface │ Attribute │ Value │
├─────────────────────┼───────────────┼─────────┤
│mkfifo(), mkfifoat() │ Thread safety │ MT-Safe │
└─────────────────────┴───────────────┴─────────┘
CONFORMING TO
mkfifo(): POSIX.1-2001, POSIX.1-2008.
mkfifoat(): POSIX.1-2008.
SEE ALSO
mkfifo(1), close(2), open(2), read(2), stat(2), umask(2), write(2), fifo(7)
COLOPHON
This page is part of release 4.04 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version
of this page, can be found at http://www.kernel.org/doc/man-pages/.
GNU 2015-03-02 MKFIFO(3)
Manual page mkfifo(3) line 59/100 (END) (press h for help or q to quit)
20220605 示例
至于为啥是0777,而不是777,,我也不了解,,,
以上是关于linux C语言mkfifo()函数 mkfifoat()函数(制作一个 FIFO 特殊文件(命名管道))的主要内容,如果未能解决你的问题,请参考以下文章
linux命令命名管道(mkfifo)+ 结合xargs命令使用