ByteDance-Backend Development Interview

  • Interview summary:
    1. Because the vote was late, one side, two sides, and three sides were held on the afternoon of October 8th. The overall interview experience is excellent. In addition to discussing project experience, the problems involved: process/thread, CPU scheduling, C/C++ string difference, three-way network handshake, four waved hands; project experience; project requirements analysis; two MySQL databases Engine, and comparison. Programming topics include: root number 2 with 10 decimal places; how to quickly determine whether a certain IP belongs to it from hundreds of thousands of IP address segments; the path whose sum in the binary tree is a certain value; does not repeat from 1-10 Choose four numbers and print all the sequence of calculations that meet the 24-point game rule.
  1. The difference between process and thread
  • During the startup of the Linux operating system, the first process started is the init process, and all other processes are its child processes;
  • Processes and threads are a description of a time period, which is a description of the CPU working time period. The main difference between processes and threads is that they are different operating system resource management methods.
  • From the perspective of the CPU, all tasks are executed one by one. The specific rotation method is: first load the context of program A, then start executing A, save the context of program A, and transfer to the next program B to be executed. Program context, and then start to execute B, save the context of program B;
  • The process is the sum of the execution time of the program including context switching = CPU loading context + CPU execution + CPU saving context;
  • A thread is a smaller CPU time period that shares the context of the process; and the process has an independent memory unit during execution, and multiple threads share memory;
  • There are multiple processes in the operating system, and each process can have 1 or more threads
  1. The smallest unit of system resource scheduling is
  • Thread is the basic unit of CPU scheduling. CPU scheduling is also called time slice scheduling. The scheduling unit is a time slice.
  1. The difference and connection between char string in C and C++ string
  • Char is to define a character, store a character, occupy a byte. Strign in C++ is a encapsulated string class;
  • There is an invisible'\0' at the end of the char string;
  • string is a part of C++ Standard Library (C++ Standard Library), need
#include <string>
  • The string.h in C provides a series of functions for manipulating char strings such as strcat, strncat, strcmp, strcpy, strstr, etc.
  • The C++ string class provides an interface for returning a char string: c_str()
  1. The network three-way handshake, four waved process
  • TCP is a connection-oriented unicast protocol. Before sending data, both parties in communication must establish a connection between each other. The so-called "connection" is actually a piece of information about each other stored in the memory of the client and server, such as ip address and port number.
  • TCP can be regarded as a byte stream, which will deal with packet loss, duplication, and errors at or below the IP layer. During the establishment of the connection, the two parties need to exchange some connection parameters. These parameters can be placed in the TCP header.
  • TCP provides a reliable, connection-oriented, byte stream, and transport layer service that uses a three-way handshake to establish a connection. Use 4 waves to close a connection.
  • The first handshake: the client sends a network packet and the server receives it. In this way, the server can conclude that the sending ability of the client and the receiving ability of the server are normal.
  • The second handshake: The server sends the package and the client receives it. In this way, the client can conclude that the receiving and sending capabilities of the server and the client's receiving and sending capabilities are normal. From the perspective of the client, I received the response packet sent by the server, indicating that the server received the network packet that I sent during the first handshake, and successfully sent the response packet, which shows that the server’s The receiving and sending capabilities are normal. On the other hand, I received a response packet from the server, indicating that the network packet I sent for the first time successfully reached the server. In this way, my own sending and receiving capabilities are also normal.
  • The third handshake: the client sends the package and the server receives it. In this way, the server can conclude that the client's receiving and sending capabilities, and the server's sending and receiving capabilities are normal. First, after the second handshake, the server does not know whether the client's receiving ability and its own sending ability are normal. In the third handshake, the server received the client's response to the second handshake. From the perspective of the server, the response data I received during the second handshake was sent out and received by the client. So, my sending ability is normal. The receiving capability of the client is also normal.
  • Waves four times: TCP connection is a peer-to-peer mode of two-way transmission, which means that both parties can send or receive data to each other at the same time. When one party wants to close the connection, it will send an instruction to inform the other party that I want to close the connection. At this time, the other party will return an ACK, and the connection in one direction is closed. But the other direction can still continue to transmit data. After all the data is sent, a FIN segment will be sent to close the connection in this direction. The receiver sends an ACK to confirm that the connection is closed.
  1. What are the MySQL database engines, introduced and compared separately
  • MySQL database has a variety of storage engines: For example: MyISAM, InnoDB, MERGE, MEMORY (HEAP), BDB (BerkeleyDB), EXAMPLE, FEDERATED, ARCHIVE, CSV, BLACKHOLE, etc., the most common ones are MyISAM and InnoDB
  • MyISAM does not support transactions, does not support fast recovery after a crash, using table locks is not suitable for high concurrency, pursuit of performance, relying on the operating system to manage the cache for reading and writing, only the index does not cache the real data, supports compression
  • InnoDB supports transactions, supports foreign keys, supports automatic disaster recovery, uses row locks to support high-concurrency reads, supports hot backup and fast recovery after crashes, and supports full-text retrieval (supported only in version 5.6.4, so some interview questions It may not be rigorous here due to time reasons), has its own read-write cache management mechanism, that is, cache indexes also cache data, and compression is not supported

Guess you like

Origin blog.csdn.net/u013894391/article/details/102408357