user3718000
user3718000

Reputation: 397

what is a socket? Is it a process?

I am studying os concepts and I found socket as the end point of communication. Now what exactly is a socket? Is it a process through means of which a system communicates? Thanks in advance

Upvotes: 2

Views: 1835

Answers (2)

Sisir
Sisir

Reputation: 5388

Most of the c-family languages and their based languages implement socket as Berkeley sockets which are implemented as file descriptors. From Wikipedia:

In the traditional implementation of Unix, file descriptors index into a per-process file descriptor table maintained by the kernel, that in turn indexes into a system-wide table of files opened by all processes, called the file table. This table records the mode with which the file (or other resource) has been opened: for reading, writing, appending, and possibly other modes. It also indexes into a third table called the inode table that describes the actual underlying files.[3] To perform input or output, the process passes the file descriptor to the kernel through a system call, and the kernel will access the file on behalf of the process. The process does not have direct access to the file or inode tables.

So on a high-level, sockets are implemented as files whose file-descriptors or handles are referenced as identifier to the socket.

Upvotes: 1

user3344003
user3344003

Reputation: 21607

From reading the Wikipedia article, I can see why you may be confused.

A socket is a virtual device. That is, it is a device that is written in software and has no physical device. Thus, you can read to and write from a socket, like you would do to a terminal.

Sockets work in pairs to communicate and are usually bidirectional. One reads to socket (A) and writes to socket (B) --- or ---- writes to socket (A) and reads from socket --- or --- switches back and forth.

Generally sockets are used for network communications. They can usually support multiple protocols (TPC/IP, UDP/IP, even DECnet--the gamut depends upon the underlying system).

Sockets can be used for interprocess communication on a single system as well.

Upvotes: 4

Related Questions