Home > Operation and Maintenance > Linux Operation and Maintenance > What does linux sock file mean?

What does linux sock file mean?

藏色散人
Release: 2023-04-12 10:48:10
Original
2131 people have browsed it

linux sock file refers to a socket file formed through shell programming; socket is an intermediate software abstraction layer for communication between the application layer and the TCP/IP protocol family. It is a set of interfaces; in the design mode, Socket In fact, it is a facade mode that hides the complex TCP/IP protocol family behind the Socket interface.

What does linux sock file mean?

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

What does linux sock file mean?

Sock in Linux generally refers to the socket file formed through shell programming. After passing ls -l, the first file type displayed is: s.

What is Socket?

1. Socket socket:

Socket originated from Unix, and one of the basic philosophies of Unix/Linux is that "everything is a file", which can be opened with "open -> ; Read and write write/read –> Operate in "close" mode. Socket is an implementation of this mode. Socket is a special file, and some socket functions are operations on it (read/write IO, open, close).

To put it bluntly, Socket is the connection between the application layer and The middle software abstraction layer for TCP/IP protocol suite communication, which is a set of interfaces. In the design mode, Socket is actually a facade mode, which hides the complex TCP/IP protocol family behind the Socket interface. For users, a set of simple interfaces is all, allowing Socket to organize data to meet the specified requirements. protocol.

Note: In fact, socket does not have the concept of layers. It is just an application of the facade design pattern, making programming easier. It is a software abstraction layer. In network programming, we use a lot of sockets.

2. The socket descriptor

is actually an integer. The three handles we are most familiar with are 0, 1, and 2. 0 is standard input, 1 is standard output, and 2 is Standard error output. 0, 1, and 2 are represented by integers, and the corresponding FILE * structures are represented by stdin, stdout, and stderr

The socket API was originally developed as part of the UNIX operating system, so the socket API Integrated with other I/O devices of the system. In particular, when an application creates a socket for Internet communication, the operating system returns a small integer as a descriptor to identify the socket. The application then passes the descriptor as a parameter and calls a function to complete some operation (such as transmitting data over the network or receiving incoming data).

In many operating systems, socket descriptors and other I/O descriptors are integrated, so applications can perform socket I/O or I/O read/write to files operate.

When an application wants to create a socket, the operating system returns a small integer as a descriptor, and the application uses this descriptor to refer to the application request that the socket requires I/O requests. The operating system opens a file. The operating system creates a file descriptor for the application to access the file. From an application's perspective, a file descriptor is an integer that an application can use to read and write files. The figure below shows how the operating system implements a file descriptor as an array of pointers that point to internal data structures.

What does linux sock file mean?

There is a separate table for each program system. To be precise, the system maintains a separate file descriptor table for each running process. When a process opens a file, the system writes a pointer to the file's internal data structure into the file descriptor table and returns the index value of the table to the caller. The application only needs to remember this descriptor and use it when manipulating the file in the future. The operating system uses this descriptor as an index to access the process descriptor table, and uses the pointer to find the data structure that holds all the information about the file.

System data structure for sockets:

1). There is a function socket in the socket API, which is used to create a socket. The general idea of ​​socket design is that a single system call can create any socket, since sockets are quite general. Once the socket is created, the application needs to call other functions to specify the specific details. For example, calling socket will create a new descriptor entry:

What does linux sock file mean?

2). Although the internal data structure of the socket contains many fields, after the system creates the socket, Most word fields are left unfilled. After the application creates the socket, it must call other procedures to populate these fields before the socket can be used.

Recommended learning: "linux video tutorial"

The above is the detailed content of What does linux sock file mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template