Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the advantages and disadvantages of using Socket in IPC

Tags:

c

sockets

I have been asked this question in some recent interviews,Whats the advantages and disadvantages of using Socket in IPC when there are other ways to perform IPC.Have not found exact answer .

Any help would be much appreciated.

like image 206
Amit Singh Tomar Avatar asked Feb 16 '12 09:02

Amit Singh Tomar


People also ask

What are the advantages of sockets?

Sockets are flexible and sufficient. Efficient socket based programming can be easily implemented for general communications. It cause low network traffic. Socket based communications allows only to send packets of raw data between applications.

What are the advantages of using socket API?

Sockets allow you to exchange information between processes on the same machine or across a network, distribute work to the most efficient machine, and they easily allow access to centralized data. Socket application program interfaces (APIs) are the network standard for TCP/IP.

What are IPC sockets?

IPC sockets (aka Unix domain sockets) enable channel-based communication for processes on the same physical device (host), whereas network sockets enable this kind of IPC for processes that can run on different hosts, thereby bringing networking into play.


1 Answers

Compared to pipes, IPC sockets differ by being bidirectional, that is, reads and writes can be done on the same descriptor. Pipes, unlike sockets, are unidirectional. You have to keep a pair of descriptors if you want to do both reads and writes.

Pipes, on the other hand, guarantee atomicity when reading or writing under a certain amount of bytes. Writing something less than PIPE_BUF bytes at once is guaranteed to be delivered in one chunk and never observed partial. Sockets do require more care from the programmer in that respect.

Shared memory, when used for IPC, requires explicit synchronisation from the programmer. It may be the most efficient and most flexible mechanism, but that comes at an increased complexity cost.

like image 146
Blagovest Buyukliev Avatar answered Oct 03 '22 07:10

Blagovest Buyukliev