Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Interprocess Communication

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Interprocess Communication

1. What is a pipe? a. Pipe is a IPC mechanism using which processes can communicate. 2. A pipe is a one-way flow of data between processes. 3. All data written to pipe is routed by the kernel to another process 4. Pipes may be considered open files that have no corresponding image in the filesystems 5. How a pipe is created? a. Using pipe() 6. What is pipe operator in unix shell? a. pipe operator in unix shell is | 7. How a pipe works? a. pipe() creates a pipe and it returns a pair of file descriptors i. Process may then pass these descriptors to its descendants through fork() ii. The processes can read from the pipe by using read() system call with the first file descriptor iii. The processes can write to the pipe by using write() system call with the second file descriptor 8. How pipe is implemented in Linux? a. In linux popen() and pclose() are used to create and close pipe. These functions are included in c library i. popen() receives two parameters filename pathname of an executable file and type string specifying the direction of data transfer 9. How popen() works in linux? a. Following operations are done by popen() i. Creates a new pipe using popen() system call ii. Forks a new process, which in turn executes the following operations If type is r, it duplicates the file descriptor associated with the pipes write channel as a file descriptor 1 (standard output); otherwise if type is w, it duplicates the file descriptor associated with pipes read channel as file descriptor 0 (Standard input) Closes the file descriptors returned by pipe() Invokes the execve() system call to execute the program specified by file name. iii. If type is r, it closes the file descriptor associated with pipes write channel; otherwise, if type is w, it closes the file descriptor associated with pipes read channel. iv. Returns the address of the FILE the file pointer that refers to whichever file descriptor for the pipe is still open b. After the popen() invocation, parent and child can exchange information through the pipe

10.

11. 12. 13. 14.

i. The parent can read (if type is r) or write (if type is w) data by using the FILE pointer returned by the function. ii. The data is written to the standard output or read from the standard input, respectively, by the program executed by child process. What are the disadvantages of Pipes? a. Pipes have no names. b. It works only between processes that have a parent process in common. POSIX defines only half duplex pipes What is a FIFO? a. FIFO is a named pipe. FIFOs are half duplex. How FIFO is created? a. FIFO is created using the mkfifo function int mkfifo (const char *pathname, mode_t mode); Arguments of mkfifo are as below path name is name of pipe mode argument specifies the file permission bits ii. The mkfifo function implies O_CREAT | O_EXCL iii. Once FIFO is created, it must be opened for reading or writing Open() or fopen() can be used A FIFO must be opened as read-only or write-only A write to a FIFO always appends the data, and a read from FIFO always returns what is at the beginning of the FIFO. What are the differences between Pipe and FIFO? a. Pipe is nameless and works with process that have a parent in common b. FIFO are name and works with unrelated processes c. To create and open a pipe requires one call to pipe. To create FIFO mkfifo is required and to open it, a call to open is required. d. A pipe automatically disappears on its last close. A FIFOs name is deleted from the file system only by calling unlink() Data in pipes and FIFOs is byte stream i.

15. 16. 17.

18.

You might also like