0% found this document useful (0 votes)
308 views7 pages

Interprocess Communication: Pipes Popen and Pclose Functions

This document discusses interprocess communication and provides details on various IPC mechanisms like pipes, FIFOs, message queues, semaphores and shared memory. It specifically describes pipes which allow for one-way communication between related processes using file descriptors. Limitations of pipes include their half-duplex nature and usage only between processes with a common ancestor. The popen and pclose functions are also summarized, allowing a process to launch a command and communicate with it via file pointers.

Uploaded by

anil_shenoy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT or read online on Scribd
0% found this document useful (0 votes)
308 views7 pages

Interprocess Communication: Pipes Popen and Pclose Functions

This document discusses interprocess communication and provides details on various IPC mechanisms like pipes, FIFOs, message queues, semaphores and shared memory. It specifically describes pipes which allow for one-way communication between related processes using file descriptors. Limitations of pipes include their half-duplex nature and usage only between processes with a common ancestor. The popen and pclose functions are also summarized, allowing a process to launch a command and communicate with it via file pointers.

Uploaded by

anil_shenoy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT or read online on Scribd
You are on page 1/ 7

Interprocess Communication


A capability supported by some operating systems that
allows one process to communicate with
another process.


Introduction

Pipes

popen and pclose functions

1
Introduction
Forms of IPC
•Pipes(half duplex)
•FIFO(named pipes)
•Stream pipes(full duplex)
•Named stream pipes B/W process on
•Message queues the same host
•Semaphores
•Shared memory
•Sockets processes on diff.
2
•Streams hosts
Pipes
#include<unistd.h>
int pipe(int filedes[2]);

filedes[0] open for reading


Filedes[1] open for writing

return 0 if ok -1 on error

333
Limitations of pipes

1.Half duplex i.e, they flow in only one direction


stream pipes overcome this limitation
2. Can be used only b/w processes having com’
ancestor
Named stream pipes get around second

4
Parent child
fork

fd[0] fd[1]
fd[0] fd[1]

pipe

kernel

Fig. HALF DUPLEX PIPE AFTER A FORK


5
Rules applies for pipes when one end is
closed

After read from a pipe whose write is closed


return 0 to indicate end of file
after we write to a pipe SIGPIPE signal is
generated.(b4 u write into any file check or else
error with errno wil b set )

6
popen and pclose functions
#include<stdio.h>
FILE *popen(const char *cmdstring,const char *type);
type r(read) or w(write)
Returns: fp if ok,null on error

int pclose(FILE *fp);


Returns : termination status of cmdstring,or -1 on error

popen does a fork and exec to execute the cmdstring


and returns a std. I/O file pointer
pclose closes the std i/o stream,waits for d cmd to
terminate and returns the termination status.
77

You might also like