1.Linux Setting Environment variables
Temporary: Export myname= "new name"
Echo $MYNAME
New name
Permanent: implemented by changing the/etc/profile
Eg:export classpath=./java_home/lib; $JAVA _home/jre/lib
Execute source/etc/profile after changing file
Features of the 2.TCP connection
(1) Connection oriented: Using C/S model
(2) Full duplex
(3) Safe and reliable:
① flow control: Solve the problem that the receiver cannot handle the data in time
② Congestion control: Addressing data loss due to network communication delays
③ error Control: Resolving data corruption, duplication, timing, and loss
(4) Byte stream based
3. Why does the TCP connection need three handshake, two times not? Why?
Two plays not allowed
Three-time handshake connection process
(1) When the connection is established, the client sends a SYN (SYN=J) packet to the server and enters the Syn_send state, waiting for the server to respond, confirm
(2) The server receives the SYN packet, must confirm the client's SYN (ACK=J+1), and also send itself a SYN packet, that is, the Syn+ack packet at this time the server enters the SYN_RECV state
(3) The client receives the server's Syn+ack packet, sends the acknowledgment packet ack (ACK=K+1) to the server, and the packet is sent to the client and server side into established state, completing three handshake
In order to ensure that the server can receive the client's information and can make the correct response to the first two handshakes, in order to ensure that the client can receive information on the server and can make the correct response to the last two times after the response
4, the principle of the implementation of the agent
Proxy server has many kinds, broadly divided into three categories: HTTP, FTP, SOCKS, which is divided into transparent proxy and opaque proxy, transparent proxy is generally a gateway for hardware
Process:
(1) The client communicates with the proxy server first, establishes the TCP connection, the destination IP is the proxy server IP
(2) The client issues a GET command that contains the URL or IP address, clear text
(3) The proxy server translates the URL into an IP address, may have DNS, copy the data from the source packet, remove the URL, and resend the package.
(4) Proxy server and real server communication, the source IP is the proxy server IP
5. What are the advantages and disadvantages of TCP and UDP respectively?
Tcp:
Advantages: Reliable and stable
TCP is reliable reflected in TCP before the transmission of data, there will be three handshake to establish the connection, and in the data transfer, there is confirmation, window, retransmission, congestion control mechanism, after the data is transmitted, will also be disconnected to save system resources
Disadvantages: slow, low efficiency, high occupancy system resources, easy to be attacked
It takes time to establish a connection before the data is passed, and when data is passed, the acknowledgement mechanism, retransmission mechanism, congestion mechanism, and so on will consume a lot of time, and all transport connections will be maintained on each device. However, each link consumes the system's CPU, memory, and other hardware resources. Because TCP has a confirmation mechanism, three handshake mechanism, which also makes TCP easy to use, to achieve DOS, DDOS, CC and other attacks
Udp:
Pros: Fast, slightly safer than TCP
UDPM does not have a variety of TCP-owned mechanisms, is a stateless transport protocol, so the transfer of data very fast, no TCP mechanisms, the use of attack less mechanisms, but also can not avoid being attacked
Cons: Unreliable, unstable
Because there are no TCP mechanisms, UDP in the transmission of data, if the network quality is not good, it will be easy to drop packets, resulting in data loss
Applicable scenarios:
TCP: When the network communication quality requirements, such as HTTP, HTTPS, FTP and other transmission of the Protocol, POP, SMTP and other mail transmission protocol
UDP: When the network communication quality requirements are not high, the need for network communication speed fast scene
6. Object-oriented and process-oriented differences
Process-oriented is to analyze the steps required to solve the problem, and then use the function to implement these steps step by one, when using a one-time call on the line.
Object-oriented is to break things up into objects, not to accomplish a single step, but to describe the behavior of something in the whole process of solving the problem. Object-oriented is to divide the problem by function rather than step
7. Process and principle of HTTP request
HTTP is stateless, meaning that the protocol has no memory capability for transactions, and the server does not know what the client state is. That is, there is no connection between opening a Web page on a server and the pages you have previously opened on this server. HTTP follows the request/response model
(1) Establishing a TCP connection
(2) Web browser sends request command to Web server
(3) Web browser sends request header information
(4) Web server Answer
(5) Web server sends answer header information
(6) Web server sends data to browser
(7) Web server shuts down TCP connection
Long and short connections for http:
In http/1.0, a short connection is used by default. That is, the browser and the server each HTTP operation, the establishment of a connection, but the end of the task is disconnected, the service side does not retain information about the connection.
From http/1.1, a long connection is used by default to maintain the connection characteristics. Using a long-connected HTTP protocol, this line of code is added to the response header:
Connection:keep-alive
In the case of a long connection, when a Web page opens, the TCP connection between the client and the server for transmitting HTTP data does not close, and if the client accesses the Web page on the server again, it will continue to use this established connection. Keep-alive does not permanently keep the connection, it has a hold time that can be set in different server software (such as Apache). Long connections are supported for both the client and the server.
The long and short connections of the HTTP protocol are essentially long connections and short connections to the TCP protocol.
Long connection short connection operation process
Operation steps for short connections:
Establish connection----data transfer-----Close connection ... Establish connection-----Data transfer----Close connection
Operation steps for long connections:
Establish a connection---data transfer. (keep connected). Data transfer---Close connection
Advantages and disadvantages of long connections and short connections
Long connections eliminate the more TCP setup and shutdown operations, reducing waste and saving time. For customers who frequently request resources, they are more suitable for long connections. However, there is a problem, as the client connection more and more, the server will not be able to carry out the time, the server side need to take some policies, such as the shutdown of some long time no read and write events occurred connection, so as to avoid some malicious connection caused server-side service damage; If the condition is allowed then the client machine can be granular, limiting the maximum number of connections per client, so that a client can be completely prevented from compromising the backend service.
Short connections are simpler for the server to manage, and the connections that exist are useful connections and do not require additional control. However, if customer requests are frequent, time and bandwidth will be wasted on TCP setup and shutdown operations.
HTTP message Format:
Request Message Format:
Request Line
Head row
Affiliated rows
Response Message Format:
8. Common HTTP status Code
Successful status code (basic starting with 2): This type of status code, representing the request has been successfully received, understood, and accepted by the server
200--the request was successful, the desired response header or data body will be returned with this response
The 202--server has accepted the request but has not processed
The 205--server successfully processed the request and did not return any content
Content is redirected (basically starting with 3): Requires the client to take further action to complete the request
301--the requested resource has been permanently moved to a new location
302--requested resource temporarily responds to request from a different URI
303--the response to the current request can be found on another URI, and the client should access that resource in a GET way
305--the requested resource must be accessed through the specified proxy
307--requested resource temporarily responds to request from a different URI
Request failed status code (basic starting with 4):
400--semantics are incorrect and the current request cannot be understood by the server. The client should not submit the request repeatedly or the request parameter is incorrect unless the modification is made
401--the current request requires user authentication
The 403--server has understood the request, but refuses to execute
404--The requested page does not exist
The request method specified in the 405--request line cannot be used to request the appropriate resource
408--Request timed out
Server-side error (Basic starting with 5): The server has an error or an abnormal state occurred while processing the request
500--Server Internal Error
503--Server is temporarily unavailable
9. What is a deadlock
Process deadlock, which is a state of operation of the operating system or system software: In a multitasking system, a deadlock occurs when one or more processes are waiting for system resources and the resources are consumed by the process itself or other processes.
Causes of deadlocks:
① system resources are low
The ② process runs in an inappropriate order
Improper allocation of ③ resources, etc.
The four necessary conditions for creating a deadlock:
① Mutex Condition: A resource can only be used by one process at a time
② request and hold condition: When a process is blocked by a request for resources, the acquired resources are left
③ conditions: Resources acquired by the process cannot be forcibly deprived until it is exhausted
④ cyclic wait condition: a cyclic waiting resource relationship between several processes is formed
Ways to avoid deadlocks:
① the orderly resource allocation method
② Banker algorithm
To resolve a deadlock:
① system reboot (most simple and rude)
② withdrawal process, deprivation of resources
Banker algorithm
Banker algorithm is one of the most representative algorithms to avoid deadlock
We can think of the operating system as bankers, and the operating system manages resources equal to the money that bankers manage, and the process asks the operating system to allocate resources equivalent to users lending to bankers. The operating system allocates resources to the process in accordance with the rules established by the banker, and when the process first requests the resources, it tests the maximum resource requirements for the process, and if the existing resources of the system can meet its maximum demand, allocate the resources according to the current amount of requests, or postpone the allocation. When a process continues to request resources in execution, it first tests the number of resources that the process has taken up and the number of resources in the application that exceed the maximum resource requirements for the process. If the allocation of resources is not exceeded, if no more than the existing resources of the test system can meet the maximum amount of resources required by the process, if it can be satisfied with the current amount of applications allocated resources, otherwise also deferred allocation.
10, Close_wait
In the case of a passive shut-down connection, the connection is in the close_wait state when the fin has been received but has not yet sent its own fin. Generally speaking, the close_wait state should be short, such as the SYN_RECV state, but in some special cases, the connection will be in a close_wait state for a long period of time. There is a large number of close_wait, the main reason is that in some cases the other side closed the socket connection, but we are busy reading or writing. Do not close the connection, the code needs to determine the socket, once read 0, disconnect, read return negative, check the errno, if not again, disconnect.
11, Time_wait
The active shutdown of the socket will enter this state, and the duration of 2MSL (maximum sub-section lifetime) length, which is an IP packet can survive on the internet for the longest time, more than this time will disappear in the network.
Role:
A: Reliable termination for TCP full-duplex connections
B: Allow old repeating sub-sections to disappear in the network
12. Inter-process communication mechanism
Pipelines, message queues, shared memory (fastest), semaphores, file mappings, anonymous/Named pipes
12 Linux OPS interview required classic written/face test