Networks, operating systems interview knowledge Lite

table of Contents

 

The difference between threads and processes

The difference between a hard link and soft link

View a threads in the process

View a folder the size of each folder

Meaning CPU load

TCP/IP

HTTP

TCP

To establish a connection: three-way handshake

Why use three-way handshake, the two will not do it

Close the connection: Four waving

Why when the connection is three-way handshake, when it is closed handshake

Sliding window protocol

And UDP difference

HTTPS


The difference between threads and processes

  1. The process is the smallest unit of resource allocation, the thread is the smallest unit of program execution
  2. Process has its own separate address space, each started a process, the system will allocate address space for it, set up a data table to maintain the code segment, stack and data segments. A thread is a shared process data space, so the CPU switching process takes than one thread is much smaller, at the same time create a thread overhead is much smaller than the process
  3. More convenient communication between threads, the thread in the same process share global variables, static variables and other data, and communication between processes carried out in a manner (IPC) communication. But how to handle the synchronization and mutual exclusion is the difficulty of writing multithreaded programs.

The difference between a hard link and soft link

Each file is created a pointer to the inode (on behalf of a physical disk blocks), you can ls -iview it.
It is to create a hard link to another file, but also by creating a pointer to the inode. When you delete a file / hard link, it will remove a pointer to the underlying inode. When all inode pointers are deleted, you will really delete files.
Soft connection is another type of file, save it is the full path to the file, it will be replaced with the absolute path access

View a threads in the process

ps -T -p <pid>

View a folder the size of each folder

du --max-depth=1 -h

Meaning CPU load

The proportion of the process over a period of time the CPU is processing and waiting to be processed and the maximum total number of treatment processes CPU. For multi-core CPU, the largest LOAD is the maximum number of cores.
Use topand top -Hpfind a relatively large thread CPU usage, and then use jstackto troubleshoot Java program

TCP/IP

Theoretical OSI seven layer network is a communication model, and TCP / IP is the actual operation of the four-layer network protocol. TCP / IP includes:

  1. Network interface layer, the host must use a protocol connected to the network
  2. The network layer, so that the host can send a packet to any network, and the packet transmitted to the target independently. IP protocol
  3. The transport layer, so that the source and the destination peer entity may be session machine. TCP and UDP protocols
  4. The application layer contains all the high-level protocol, FTP / TELNET / SMTP / DNS / NNTP / HTTP

HTTP

HTTP is a TCP / IP application layer protocol [protocol]. It does not relate to data packet transmission, the main communication format predetermined between the client and the server, the information exchange is the most commonly used Internet protocol

Features:

  1. Simple and fast. Only need to pass the request method [] and [resource] path will be able to determine the resource
  2. Flexible, any type of transmission [Data]
  3. No connection, generally only one request a connection, the connection is released after the end of the active, but HTTP1.1 keep-alive may be used to multiplex a plurality of the same TCP connection request transmitted
  4. Stateless, after the client sends an HTTP request to the server, the server will send data over us, but does not record any information. So Cookie, Session had.

TCP

TCP is a connection-oriented, reliable, based on the TCP / IP protocol in the byte stream transport layer [protocol]

 

To establish a connection: three-way handshake

  1. When connection is established, the client sends syn packets (syn = j) to the server, and enters the SYN_SENT state, waiting for the server to confirm; SYN: synchronization sequence number (Synchronize Sequence Numbers).
  2. Syn server receives the packet, you must confirm the customer SYN (ack = j + 1), while themselves sends a SYN packet (syn = k), i.e., SYN + ACK packet, then the server enters a state SYN_RECV;
  3. Client receives the SYN + ACK packet to the server, the server sends an acknowledgment packet ACK (ack = k + 1), this packet is sent, the client and server into the ESTABLISHED (TCP connection succeeds) state, to complete the three-way handshake.

Why use three-way handshake, the two will not do it

To avoid delays due to network problems led to the creation of invalid connection. For example, a client sends a connection request is not lost, but for a long time in a network node stranded, and after that to the connection release service before reaching the end, if you do not use three-way handshake, once the server connection is a connection request but the connection request has expired, server-side resources will be wasted.

Close the connection: Four waving

  1. When the application notifies the host A TCP data has already been sent, TCP segments sent with a FIN packet to the host B additional marks (FIN represents English finish).
  2. After the host B receives the FIN segment does not immediately respond to the host with a FIN segment A, but sends an acknowledgment ACK sequence number Xianxiang host A, while notifying its own corresponding application: Partner close the connection (the first transmission the purpose is to prevent the ACK within this period of time, retransmit the other FIN segment).
  3. Application host B told TCP: I want to completely close the connection, TCP sends a FIN segment to the host A.
  4. After Host A receives the FIN segment, transmits ACK to the host B represents a complete release of the connection.

Why when the connection is three-way handshake, when it is closed handshake

Because when the terminal receives SYN Server Client terminal connection request message may be sent directly SYN + ACK packet. Wherein the ACK message is used for response, SYN etc is used to synchronize the packet. But the connection is closed, when the Server side FIN packet is received, probably does not close immediately SOCKET, it can only respond to a first ACK packet, told Client-side, "you send FIN messages I have received." Only until the end of all my Server messages are sent over, I can send FIN packets, and therefore can not be sent together. It requires a four-step handshake.

Sliding window protocol

Sliding window protocol for the transport layer is a measure of flow control, the receiver by the sender their advertisement window size, thereby controlling the transmission speed of the transmitting side, thus preventing send rate too fast, their purpose being submerged.

ACK contains two very important information: One expects to receive the next byte of the serial number n, n represents the recipient has received the previous n-1 bytes of data. Second, the current window size m, so the sender after receiving the ACK contains two data can be calculated how many bytes of data can also be transmitted to the other party, which is the basic principle of sliding window flow control

TCP sliding window is dynamic, application when needed (e.g., insufficient memory), the notification API by the TCP stack TCP receive window is reduced. Then TCP protocol stack includes the new window size notification sent to the next segment to the end of the window is notified terminal changes the transmission window, in order to achieve the object of the slow transmission rate.

And UDP difference

  • TCP provides a reliable connection-oriented data stream transmission, and unreliable transmission of UDP data stream to provide a non-connection-oriented, such as QQ
  • TCP require data security, UDP data transfer speed, since no connection waiting, much less operate, but its safety has generally
  • Protocol (FTP / SMTP / HTTP) TCP corresponds, UDP (DNS)

HTTPS

HTTPS protocol is constructed from SSL + HTTP protocol can be encrypted transmission, network authentication protocol than http protocol security to prevent data theft during transmission, change, ensure data integrity, it greatly increases the middleman the attack cost.

The encryption process:

  1. Hello - Hello handshake starts sending messages to the client. In order to contain all the information server connected to the client through SSL, including various versions of SSL cipher suites and the maximum supported by the client. Hello server returns a message containing similar information the client needs, including in the end which one to use encryption and SSL version.
  2. Certificate exchange - now the connection is established, the server must prove his identity by SSL certificates. SSL certificate contains a variety of data including owner name, associated attributes (domain name), the public key certificates, digital signatures and information about the validity of the certificate. The client checks that it is not being verified CA and the digital signature to verify that the contents have been modified. Note that the server is allowed to demand a certificate to prove the identity of the client, but this occurs only in sensitive applications.
  3. Key Exchange - using asymmetric RSA public key encryption algorithm (the client generates a symmetric key, the symmetric key is then encrypted with the public key server SSL certificate inner tube is then sent to the server, the server using the server private key to decrypt. , this handshake phase is complete.) or DH exchange algorithm in both the client and server-side to determine the key to be used. The key is a simple, symmetric key mutually agreed. This process is based on asymmetric encryption and the server's public / private key.
  4. Encrypted communication - the actual information encrypted on the server and the client is to use symmetric encryption algorithm, which algorithm has been used to determine the stage at Hello. Symmetric encryption algorithm for encryption and decryption keys are very simple. This key is based on the third step in the client and server have negotiated good. In contrast with the asymmetric encryption algorithm requires a public key / private key.
Published 142 original articles · won praise 31 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_38905818/article/details/103817320