Skip to content

mkfifo command in Linux

The mkfifo command in Linux is used to create named pipes, which are special types of files that allow inter-process communication. With mkfifo, you can establish communication channels between different processes for seamless data transfer. This command is particularly useful in shell scripting and when working with multiple programs that need to pass data to each other efficiently. Named pipes created with mkfifo can help streamline your workflow and improve the overall efficiency of your system.

Terminal window
mkfifo [option] [parameter]
OptionDescription
-mSet the permission mode of the fifo
-ZSet the SELinux security context
ParameterDescription
pathSpecify the path for the fifo to be created
Terminal window
mkfifo mypipe

Creates a named pipe called “mypipe”.

Terminal window
file mypipe

Displays the file type of “mypipe” which should show “fifo”.

Terminal window
cat mypipe

Reads data from the named pipe “mypipe”.

Terminal window
echo "Hello, named pipe!" > mypipe

Writes the text “Hello, named pipe!” to the named pipe.

Terminal window
mkfifo pipe

Creates a named pipe called “pipe” for piping data between commands.

Use named pipe for inter-process communication

Section titled “Use named pipe for inter-process communication”
Terminal window
mkfifo communication_pipe

Creates a named pipe “communication_pipe” for inter-process communication.

Terminal window
ls -l > my_data_pipe

Redirects the output of the “ls -l” command to a named pipe called “my_data_pipe”.

Terminal window
rm mypipe

Removes the named pipe “mypipe” from the filesystem.

To use the mkfifo command in Linux, execute the following command:

Terminal window
mkfifo /path/to/named_pipe

How can I create multiple named pipes with mkfifo?

Section titled “How can I create multiple named pipes with mkfifo?”

You can create multiple named pipes at once using the mkfifo command by providing the names of the pipes as arguments. For example:

Terminal window
mkfifo pipe1 pipe2 pipe3

How can I check the permissions of a named pipe created with mkfifo?

Section titled “How can I check the permissions of a named pipe created with mkfifo?”

You can use the ls command with the -l option to view the permissions of a named pipe created with mkfifo. For example:

Terminal window
ls -l /path/to/named_pipe

Can mkfifo be used to create FIFOs with specific permissions?

Section titled “Can mkfifo be used to create FIFOs with specific permissions?”

Yes, you can specify the permissions for the named pipe created with mkfifo using the chmod command. For example:

Terminal window
mkfifo /path/to/named_pipe
chmod 777 /path/to/named_pipe

How can I remove a named pipe created with mkfifo?

Section titled “How can I remove a named pipe created with mkfifo?”

To remove a named pipe created with mkfifo, you can use the rm command. For example:

Terminal window
rm /path/to/named_pipe

Can I use mkfifo to create named pipes in a specific directory?

Section titled “Can I use mkfifo to create named pipes in a specific directory?”

Yes, you can specify the directory where you want to create the named pipe using the mkfifo command. For example:

Terminal window
mkfifo /path/to/directory/named_pipe

How can I read from a named pipe created with mkfifo?

Section titled “How can I read from a named pipe created with mkfifo?”

You can read from a named pipe created with mkfifo using standard file I/O operations in bash scripts or other programming languages. For example:

Terminal window
cat /path/to/named_pipe

Is it possible to write data to a named pipe using mkfifo?

Section titled “Is it possible to write data to a named pipe using mkfifo?”

Yes, you can write data to a named pipe created with mkfifo using standard file I/O operations in bash scripts or other programming languages. For example:

Terminal window
echo "Data to write" > /path/to/named_pipe

Can a named pipe created with mkfifo be used for inter-process communication?

Section titled “Can a named pipe created with mkfifo be used for inter-process communication?”

Yes, named pipes created with mkfifo can be used for inter-process communication by enabling communication between multiple processes through reading and writing to the named pipe.

  • Creating named pipes for inter-process communication
  • Setting up communication channels between processes
  • Implementing communication mechanisms in shell scripts
  • Providing a method for one-way communication between processes