MKFIFO(3POSIX)
π MKFIFO β the POSIX Programmer's Manual glow-up π
okay bestie, so this is the mkfifo page from the POSIX Programmer's Manual (yes, the whole 3POSIX situation, it's giving β¨standardsβ¨). sit down, grab a strawberry drink π, and let's get into it.
PROLOG π«Ά β real talk first: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may just not be implemented on Linux at all. π
β¨ NAME β¨
mkfifo, mkfifoat β make a FIFO special file πΈ
β¨ SYNOPSIS β¨
#include <sys/stat.h>
int mkfifo(const char *path, mode_t mode);
#include <fcntl.h>
int mkfifoat(int fd, const char *path, mode_t mode);
β¨ DESCRIPTION β¨
so the mkfifo() function shall create a new FIFO special file, and that file is named by the pathname that path is pointing to. the file permission bits of the new FIFO get initialized from mode, and β iconic detail β the file permission bits of the mode argument get modified by the process' file creation mask. π
when bits in mode other than the file permission bits are set, the effect is implementation-defined. (iykyk β don't @ me, that's just what the standard says.)
if path names a symbolic link, mkfifo() shall fail and set errno to [EEXIST]. no wiggle room bestie.
the FIFO's user ID shall be set to the process' effective user ID. the FIFO's group ID shall be set to the group ID of the parent directory or to the effective group ID of the process. implementations shall provide a way to initialize the FIFO's group ID to the group ID of the parent directory. implementations may, but need not, provide an implementation-defined way to initialize the FIFO's group ID to the effective group ID of the calling process. π
upon successful completion, mkfifo() shall mark for update the last data access, last data modification, and last file status change timestamps of the file. also β and this part is so important β the last data modification and last file status change timestamps of the directory that contains the new entry shall be marked for update. the directory is also having a moment. π
now, mkfifoat() shall be equivalent to mkfifo() except in the case where path specifies a relative path. in that case, the newly created FIFO is created relative to the directory associated with the file descriptor fd instead of the current working directory. if the access mode of the open file description associated with the file descriptor is not O_SEARCH, the function shall check whether directory searches are permitted using the current permissions of the directory underlying the file descriptor. if the access mode is O_SEARCH, the function shall not perform the check. (no check needed, we already know her π«Ά)
if mkfifoat() is passed the special value AT_FDCWD in the fd parameter, the current working directory shall be used and the behavior shall be identical to a call to mkfifo(). twins fr fr.
β¨ RETURN VALUE β¨
upon successful completion, these functions shall return 0. otherwise, these functions shall return -1 and set errno to indicate the error. and if -1 is returned, no FIFO shall be created. π (she said no.)
β¨ ERRORS β¨
these functions shall fail if:
EACCESβ a component of the path prefix denies search permission, or write permission is denied on the parent directory of the FIFO to be created. π€EEXISTβ the named file already exists. bestie it's taken.ELOOPβ a loop exists in symbolic links encountered during resolution of thepathargument. πENAMETOOLONGβ the length of a component of a pathname is longer than{NAME_MAX}.ENOENTβ a component of the path prefix ofpathdoes not name an existing file, orpathis an empty string. π«₯ENOENTorENOTDIRβ thepathargument contains at least one non-<slash>character and ends with one or more trailing<slash>characters. ifpathwithout the trailing<slash>characters would name an existing file, an[ENOENT]error shall not occur. (so close but so specific π)ENOSPCβ the directory that would contain the new file cannot be extended, or the file system is out of file-allocation resources. the vibes are dry, there's no room.ENOTDIRβ a component of the path prefix names an existing file that is neither a directory nor a symbolic link to a directory. π«EROFSβ the named file resides on a read-only file system. frozen. βοΈ
the mkfifoat() function shall fail if:
EACCESβ the access mode of the open file description associated withfdis notO_SEARCHand the permissions of the directory underlyingfddo not permit directory searches.EBADFβ thepathargument does not specify an absolute path and thefdargument is neitherAT_FDCWDnor a valid file descriptor open for reading or searching.ENOTDIRβ thepathargument is not an absolute path andfdis a file descriptor associated with a non-directory file.
these functions may fail if:
ELOOPβ more than{SYMLOOP_MAX}symbolic links were encountered during resolution of thepathargument. ππENAMETOOLONGβ the length of a pathname exceeds{PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds{PATH_MAX}.
okay so heads up: the following sections are informative. they're the β¨bonus contentβ¨, not the rules-rules.
β¨ EXAMPLES β¨
Creating a FIFO File π
the following example shows how to create a FIFO file named /home/cnd/mod_done, with read/write permissions for owner, and with read permissions for group and others. iconic permission spread tbh.
#include <sys/types.h>
#include <sys/stat.h>
int status;
...
status = mkfifo("/home/cnd/mod_done", S_IWUSR | S_IRUSR |
S_IRGRP | S_IROTH);
β¨ APPLICATION USAGE β¨
None. π (yes bestie, that's it, nothing to see here, move along)
β¨ RATIONALE β¨
the syntax of this function is intended to maintain compatibility with historical implementations of mknod(). the latter function was included in the 1984 /usr/group standard but only for use in creating FIFO special files. the mknod() function was originally excluded from the POSIX.1β1988 standard as implementation-defined and replaced by mkdir() and mkfifo(). the mknod() function is now included for alignment with the Single UNIX Specification. glow-up arc fr. π
the POSIX.1β1990 standard required that the group ID of a newly created FIFO be set to the group ID of its parent directory or to the effective group ID of the creating process. FIPS 151β2 required that implementations provide a way to have the group ID be set to the group ID of the containing directory, but did not prohibit implementations also supporting a way to set the group ID to the effective group ID of the creating process. conforming applications should not assume which group ID will be used. if it matters, an application can use chown() to set the group ID after the FIFO is created, or determine under what conditions the implementation will set the desired group ID. (basically: don't assume, go check, or just fix it yourself π
)
the purpose of the mkfifoat() function is to create a FIFO special file in directories other than the current working directory without exposure to race conditions. any part of the path of a file could be changed in parallel to a call to mkfifo(), resulting in unspecified behavior. by opening a file descriptor for the target directory and using the mkfifoat() function it can be guaranteed that the newly created FIFO is located relative to the desired directory. no race conditions, no drama, main character energy only. π
β¨ FUTURE DIRECTIONS β¨
None. π¦ (nothing on the horizon, she's perfect as she is)
β¨ SEE ALSO β¨
chmod()mknod()umask()
The Base Definitions volume of POSIX.1β2017:
<fcntl.h><sys_stat.h><sys_types.h>
β¨ COPYRIGHT β¨
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
π and that's the whole page, bestie!! brought to you by IEEE/The Open Group, 2017, straight out of the MKFIFO(3POSIX) manual β go forth and make FIFOs responsibly π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms