What is the difference between mkfifo() and mknod() while creating a named pipe?
I tried searching but couldn't get a satisfactory answer.
Using mkfifo()
is standardized and portable. Using mknod()
in general, is not portable — it is a part of POSIX (despite a statement to the contrary in an earlier version of this answer). The POSIX specification says that mkfifo()
should be preferred. Otherwise, there is no difference between a FIFO created by mkfifo()
and mknod()
.
Note that mknod()
can be used to create other device types than just FIFOs. It can create block special and character special devices. Once upon a very (very, very) long time ago, mknod()
was used to create directories too — in the days before there was a mkdir()
or rmdir()
system call. After creating the directory, you had to use link()
twice to create the .
and ..
entries in the new directory. (And you had to have root privileges to use it, so the mkdir
and rmdir
commands were SUID root.) File systems are a lot more reliable nowadays because that's no longer part of the game.
Reference: Version 7 Unix — circa 1979.