Yes, it's equivalent, but obviously only if you tell mknod
to actually create a FIFO, and not a block or character device (rarely done these days as devtmpfs/udev does it for you).
mkfifo foobar
# same difference
mknod foobar p
In strace
it's identical for both commands:
mknod("foobar", S_IFIFO|0666) = 0
So in terms of syscalls, mkfifo
is actually shorthand for mknod
.
The biggest difference, then, is in semantics. With mkfifo
you can create a bunch of FIFOs in one go:
mkfifo a b c
With mknod
, since you have to specify the type, it only ever accepts one argument:
# wrong:
$ mknod a b c p
mknod: invalid major device number ‘c’
# right:
mknod a p
mknod b p
mknod c p
In general, mknod
can be difficult to use correctly. So if you want to work with FIFO, stick to mkfifo
.
mkfifo(2)
really is a separate system call frommknod(2)
(but it'll end up doing exactly the same thing asmknod(S_FIFO)
). – Jul 28 '19 at 14:30mkfifo
andmknod
are actually programs using themknod
system call (didn't knew of that system call before today) to create a FIFO. You use the terms "FIFO" and "named" interchangeably, I guess. Are they the same thing? Bi-directional named pipes are implemented by means of Unix domain sockets, right? – Shuzheng Jul 29 '19 at 12:21