Pipes are used to pass data between related processes. It is an unidirectional channel through which data flows. If a command such as ls -l |grep .c is given, grep .c command will read the output from ls -l. Once both the processes have finished executing, the shell displays output of the last command in the pipe. The <unistd.h> library provides functions such as pipe, read, and write for creating and using pipes.
Functions used in pipe:
– int π©π’π©π(int pipefd[2]);
– ssize_t π«πππ(int fd, void *buf, size_t count);
– ssize_t π°π«π’ππ(int fd, const void *buf, size_t count);
– int ππ₯π¨π¬π(int fd)
FIFO mechanism is similar to pipe. FIFO is called as named pipe. A FIFO has write end and a read end ad adata is read from the pipe in the same as it is written. Since it is named, it can be used for communication between unrelated processes. mkfifo() system called is used for the creation of fifo. It will provide synchronization between the processes. If the reading process attempts to read from an empty pipe, it will block until data is available. Similarly, if the writing process attempts to write to a full pipe, it will block until space becomes available. The Kernel maintains exactly one pipe object for each FIFO special file that is opened by atleast one process.
Functions used in fifo:
– int Β π¦π€ππ’ππ¨(const char *pathname, mode_t mode);
– int π¨π©ππ§(const char *pathname, int flags);
– ssize_t π«πππ(int fd, void *buf, size_t count);
– ssize_t π°π«π’ππ(int fd, const void *buf, size_t count);
– int ππ₯π¨π¬π(int fd);
Message queues are similar to pipes. As the message boundaires are reserved, the reading process and writing process communicate in units of messages and each message includes an interger type field where it is possible to select a message by its type rather than reading in the order they are sent. msgget(), msgsnd(), msgrcv(), msgctl() are used for creation , sending, receiving and control the message queues.
Functions used in Message queues:
– int π¦π¬π π ππ(key_t key, int msgflg);
– int π¦π¬π π¬π§π(int msqid, const void *msgp, size_t msgsz, int msgflg);
– ssize_t π¦π¬π π«ππ―(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);
– int π¦π¬π πππ₯(int msqid, int cmd, struct msqid_ds *buf);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An Article by: Yashwanth Naidu Tikkisetty
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
