[c/c++ Back-end development face classics series] 1 Convinced face classics

The content and opinions in this series are only personal feelings, and the wrong things are directly private! The purpose is for everyone to better understand the difficulty of the interview questions and how to prepare. I hope that everyone will waste less time looking for information and learn more about dry goods (the dry goods are here )! Due to space reasons, most of the topics are concise, but there are related books recommended for reading, hope for your understanding!

Sangfor prefers security companies. The technology stack c/c++ series are too many.

1. Interview situation

Note that some students may not need the written test. By looking for introductory comments from Niuke, the interview will be notified directly if the resume is qualified. The efficiency is very high (I am very impressed by this), and there is no delay in each, if it is suitable for two or three days As a result, inappropriate is a mismatch!

1 side (25 minutes by phone)

On the one hand, it focuses on the basics of c/c++ grammar.

  • Self introduction

Name, school, matching degree with position, etc.

  • Blocking non-blocking difference

Blocking, non-blocking : whether the data to be accessed by the process/thread is ready, whether the process/thread needs to wait;

Synchronous, asynchronous : the way to access data, synchronization requires active reading and writing of data, and it will still block in the process of reading and writing data; asynchronous only requires notification of completion of I/O operation, and does not actively read and write data, which is completed by the operating system kernel Data reading and writing.


For Unix: blocking I/O (default), non-blocking I/O (nonblock), I/O multiplexing (select/poll/epoll) are all synchronous I/O , because they are in the data space by the kernel Copying back to the process buffer is blocked (cannot do other things). Only the asynchronous I/O model (AIO) is consistent with the meaning of asynchronous I/O operations, that is, the process is notified after 1 data preparation is completed and 2 is copied back to the buffer from the kernel space. You can do something else while waiting for the notification. Thing.

  • How to call each other in c/c++

(1) C calls C++ functions or variables, which are declared as extern "C" in the C++ header file  . Only extern declarations are used when C calls.

(2) extern "C" {}, the declaration is used in C++, telling the compiler to use C to generate (or find) the target symbol for the function or variable declared in {}.

  • How to deal with zombie processes

If the parent process terminates before the child process, the parent process of all child processes will be changed to init process, we call these processes adopted by the init process. Then use the ps command to review the parent can see the child process has become ppid 1.


When the child process terminates before the parent process, the kernel saves a certain amount of information for each terminated child process, so when the parent process of the terminated process calls wait or waitpid, this information can be obtained. This information includes at least the process ID, the termination status of the process, and the total amount of CPU time used by the process. The storage area used by other processes, open files will be released by the kernel.


If the child process has been terminated, but the parent process has not yet processed it (obtain information about the termination of the child process, release the resources it still occupies) process is called a zombie process . ps command status zombie print as the Z- .

When the child process terminates , the kernel will send a SIGCHLD signal to its parent process, the parent process can choose to ignore the signal, or provide a processing function after receiving the signal. The default action for this signal is to ignore it.

We don't want too many zombie processes to be generated, so when the parent process receives the SIGCHLD signal, it should call the wait or waitpid function to deal with the child process and release the resources occupied by the child process.


In the UNIX system, a process ends, but its parent process does not wait for him (call wait / waitpid), then it will become a zombie process. (You can check the zombie process through the Z mark in the process table)

  • How to deal with the loss of the second handshake in the three-way handshake

In the three-way handshake protocol, the server maintains an unconnected queue . This queue opens an entry for each client's SYN packet. The entry indicates that the server has received the SYN packet and sends a confirmation to the client, and is waiting for the client's confirmation packet. The connection identified by these entries is in the SYN_RECV state on the server. When the server receives the client's confirmation packet, it deletes the entry and the server enters the ESTABLISHED state.


Three-way handshake agreement

After the server sends the SYN-ACK packet, if it does not receive the client confirmation packet, the server retransmits it for the first time, waits for a period of time and does not receive the client confirmation packet, and then performs the second retransmission. If the number of retransmissions exceeds the maximum retransmission specified by the system Transmission times, the system deletes the connection information from the semi-connection queue.

The semi-connection survival time refers to the longest time the entry of the semi-connection queue survives, that is, the longest time from the server receiving the SYN packet to confirming that the packet is invalid. This time value is the longest waiting time for all retransmission request packets sum. Sometimes we also call the half-connection survival time as Timeout time and SYN_RECV survival time.

  • What does the send function successfully indicate

send() is used to send data to a connected socket. If there is no error, the return value is the total number of data sent, otherwise it returns SOCKET_ERROR. Note that the successful completion of the send() call does not mean that the data transfer has arrived. Just put the data in the buffer , the data transmission depends on the established TCP link.

  • When did the time_wait state occur

When the active closing party receives the FIN packet from the passive closing party and sends an ACK, it enters TIME_WAIT

1) Reliably realize the termination of TCP full-duplex connection


In the four-way handshake process of the TCP protocol to close the connection, the final ACK is sent by the end that actively closed the connection (hereinafter collectively referred to as end A). If this ACK is lost, the other party (hereinafter collectively referred to as end B) will resend the final FIN. Therefore, the A side must maintain state information (TIME_WAIT) to allow it to retransmit the final ACK. If the A side does not maintain the TIME_WAIT state, but is in the CLOSED state, then the A side will respond to the RST section, and the B side will interpret this section as an error after receiving it (a connection reset SocketException will be thrown in java).

Therefore, to realize the normal termination of the TCP full-duplex connection, the loss of any one of the four subsections during the termination process must be handled, and the A end that actively closes the connection must maintain the TIME_WAIT state.


2) Allow old repetitive sections to disappear in the network

The TCP segment may be "lost" due to a router abnormality. During the lost period, the TCP sender may resend this segment due to an acknowledgement timeout. The lost segment will also be sent to the final destination after the router is repaired. This is late. It may cause problems when the stray section arrives. After closing the "previous connection", a "new connection" between the same IP and port is immediately re-established. The lost and repeated packets of the "previous connection" arrive after the termination of the "previous connection", and are " New connection" received. In order to avoid this situation, the TCP protocol does not allow a connection in the TIME_WAIT state to start a new available connection. Because the TIME_WAIT state lasts for 2MSL, it can ensure that when a new TCP connection is successfully established, the duplicate packets from the old connection have disappeared in the network. .

  • How does tcp ensure reliability

TCP provides a connection-oriented, reliable byte stream service.
Connection-oriented: It means that two applications using TCP (usually a client and a server) must establish a TCP connection before exchanging data with each other. In a TCP connection, only two parties communicate with each other. Broadcast and multicast cannot be used for TCP.
TCP provides reliability in the following ways:


1、应用数据被分割成TCP认为最适合发送的数据块。这和UDP完全不同,应用程序产生的数据报长度将保持不变。                                                                 (将数据截断为合理的长度)
2、当TCP发出一个段后,它启动一个定时器,等待目的端确认收到这个报文段。如果不能及时收到一个确认,将重发这个报文段。(超时重发)


3、当TCP收到发自TCP连接另一端的数据,它将发送一个确认。这个确认不是立即发送,通常将推迟几分之一秒 。 (对于收到的请求,给出确认响应) (之所以推迟,可能是要对包做完整校验)


4、 TCP将保持它首部和数据的检验和。这是一个端到端的检验和,目的是检测数据在传输过程中的任何变化。如果收到段的检验和有差错,TCP将丢弃这个报文段和不确认收到此报文段。(校验出包有错,丢弃报文段,不给出响应,TCP发送数据端,超时时会重发数据)


5、既然TCP报文段作为IP数据报来传输,而IP数据报的到达可能会失序,因此TCP报文段的到达也可能会失序。如果必要,TCP将对收到的数据进行重新排序,将收到的数据以正确的顺序交给应用层。 (对失序数据进行重新排序,然后才交给应用层)


6、既然IP数据报会发生重复,TCP的接收端必须丢弃重复的数据。(对于重复数据,能够丢弃重复数据)


7、TCP还能提供流量控制。TCP连接的每一方都有固定大小的缓冲空间。TCP的接收端只允许另一端发送接收端缓冲区所能接纳的数据。这将防止较快主机致使较慢主机的缓冲区溢出。(TCP可以进行流量控制,防止较快主机致使较慢主机的缓冲区溢出)TCP使用的流量控制协议是可变大小的滑动窗口协议。
字节流服务::
两个应用程序通过TCP连接交换8bit字节构成的字节流。TCP不在字节流中插入记录标识符。我们将这称为字节流服务(bytestreamservice)。



TCP对字节流的内容不作任何解释:: TCP对字节流的内容不作任何解释。TCP不知道传输的数据字节流是二进制数据,还是ASCII字符、EBCDIC字符或者其他类型数据。对字节流的解释由TCP连接双方的应用层解释。

  • seq为1000,发送了1000个数据,下一个seq是多少?

2001

  • 使用过捕包工具吗,说一下抓一个明文http过程

讲述一下wireshark使用方法,以及http明文并可扩展到密文https。

  • gcc优化参数介绍几个

-O设置一共有五种:-O0、-O1、-O2、-O3和-Os。

-O0:这个等级(字母“O”后面跟个零)关闭所有优化选项,也是CFLAGS或CXXFLAGS中没有设置-O等级时的默认等级。这样就不会优化代码,这通常不是我们想要的。 


-O1:这是最基本的优化等级。编译器会在不花费太多编译时间的同时试图生成更快更小的代码。这些优化是非常基础的,但一般这些任务肯定能顺利完成。


-O2:-O1的进阶。这是推荐的优化等级,除非你有特殊的需求。-O2会比-O1启用多一些标记。设置了-O2后,编译器会试图提高代码性能而不会增大体积和大量占用的编译时间。

-O3:这是最高最危险的优化等级。用这个选项会延长编译代码的时间,并且在使用gcc4.x的系统里不应全局启用。自从3.x版本以来gcc的行为已经有了极大地改变。在3.x,-O3生成的代码也只是比-O2快一点点而已,而gcc4.x中还未必更快。用-O3来编译所有的软件包将产生更大体积更耗内存的二进制文件,大大增加编译失败的机会或不可预知的程序行为(包括错误)。这样做将得不偿失,记住过犹不及。在gcc 4.x.中使用-O3是不推荐的。

-Os:这个等级用来优化代码尺寸。其中启用了-O2中不会增加磁盘空间占用的代码生成选项。这对于磁盘空间极其紧张或者CPU缓存较小的机器非常有用。但也可能产生些许问题,因此软件树中的大部分ebuild都过滤掉这个等级的优化。使用-Os是不推荐的。

二面(50分钟)

一面到二面间隔了30分钟。我的深信服二面全是项目面,所以在简历上一般把自己更加熟悉的项目放在上面,不过问题不大,因为一般面试官会说:"请介绍一下你熟悉的项目"。那么鉴于每个人的项目不同,我就在这提上几点可能是公共的问题。稍微详细的可以参考写简历这几点一定要注意!

  • 项目背景,项目人员构成,自己所担任角色

  • 你在此项目中做了什么

  • 在做这个项目中的难点是什么,又遇到困难?如何解决的

  • 项目扩展性如何?

三面(30分钟)

我也不知道三面是个什么意思,深信服大部分都是一共三面。在我的记忆里,三面面试官很和蔼,跟我说了一下规划,甚至聊了下他以前的故事,so,这里的三面也给大家带来不了什么。

四面(hr面)

hr都是我的偶像,他们的应变能力让小蓝常常不知所措。比如上一句问你最讨厌的人,下一句就是如果以后你的上司也是这样的怎么处理呢,哭唧唧!下面也整理一下hr常问问题

  • 你最擅长的技术方向是什么?

  • 现在几个offer?

  • 最大优缺点

  • 对加班的看法

  • 薪资的要求

  • 工作中你难以和同事,上司相处,你该怎么办?


Guess you like

Origin blog.51cto.com/14984904/2545752