Sei sulla pagina 1di 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

Potrebbero piacerti anche