C++ background Tencent WXG internship interview (has taken offer)

When: April 16, 2018

Position: C/C++ background development (Linux)

BG:WXG

About me: Undergraduate junior is expected to graduate in 2019

 

One side (general technical side)

 

Process: submit resume -> tear code -> start interview -> end

Time: about 1 hour

Hand tearing code: a binary search tree to find the kth largest node in the tree

After getting the title, I didn't think about it. I wanted to use in-order traversal and put the traversal results into a queue with a capacity of k (basic operation). But why write down the vector easily? ? ? The interviewer looked at what I wrote after seeing me writing down so quickly, and reminded me that I couldn't save it. After thinking for less than 30 seconds, I panicked, and then quickly calmed down. The second idea: use recursive in-order traversal to convert the binary search tree into a doubly linked list, and then traverse the linked list for k steps to find the kth largest node or return NULL to indicate that k is invalid. When I was writing in the middle, the interviewer looked at the code I wrote, then asked me about my ideas, and then introduced it to him. When he was about to finish writing, he said that I just wanted to test your in-order traversal. I said that I can't dump it, but I can still use the stack... (Is it wrong for me to use the queue...)

 

Start the interview:

 

fork process

Q: Introduce the process of fork

A: From the source code, fork simply copies almost everything of the parent process, such as the address space of the parent process, opened file descriptors, namespaces, etc... and then modify Some flags make themselves different from the parent process

Q: Will the stack and heap be copied?

A: emmm... yes

Q: What will be done before copying

A: emmm... (thought for a long time, didn't do anything...)

Q: What about the structure representing the process, will it be copied?

A: Is task_struct? Yes, yes, before that, a PCB will be allocated from the slab...

FIXME: copy-on-write not expressed

The difference between fork, vfork and clone

Q: Introduce the difference between fork, vfork and clone

A: From the source code analysis, they are all used to create Linux lightweight processes. The difference between vfork and fork is that vfork shares the address space of the parent process. After vfork, the parent process will let the self process run first, because vfork is mainly used for In order for the child process to exec, the child process will refresh the memory with the data of the new program after exec, so that it has its own address space. After the child process is exec, it will send a signal to the parent process. At this time, the parent process can start running. If the child process modifies the address space of the parent process, the parent process will find that its data has been changed when it wakes up. lost, so this is not safe. As for clone, it provides options to let you choose what to copy each time, but it still calls do_fork like...

zombie process

Q: Introduce the zombie process

A: Zombie processes are processes that have not been waited by the parent process after death. After they run, the PCB resources have not been released, waiting for the parent process to wait for them to obtain their status. If the parent process does not wait, there will be too many zombie processes and a lot of unreleased resources. At this time, system performance will be affected. If the parent process dies early, the child process will be hosted to the process with pid 1. It used to be init and now it is systemd. It will wait for all dead child processes regularly.

Q: How to avoid zombie processes?

A: A single thread wait child process, or emmm... There are two signals, one SIGCHLD, one SIGCLD, set the processing mode of these two signals to ignore, they tell the kernel, do not care about the state of the end of the child process, so when the child Just release all resources when the process terminates. The difference between them is that SIGCLD will also check whether there is an terminated child process when the signal handler is installed. If there is, it will call the signal handler, but SIGCHLD will not, that is, it may lose the fact that the existing child process has ended.

Explain the reference from the assembly level

Q: Explain the quotation from the assembly

A: Let's take a look at the lvalue reference first (drawing diagram). The lvalue reference encapsulates a pointer, and the pointer points to the referenced object. Every time this reference is used, the encapsulated pointer is dereferenced. In the case of rvalue reference, the bottom layer is to make a memory copy of the original object, and then encapsulate the pointer to this copy. Because it is a copy, the rvalue reference is actually an lvalue. There is a forkward function in emmm...STL, and its function is to restore the type of rvalue reference...

The shocking herd effect, how to avoid it

Q: Do you understand the shocking herd effect?

A: Is there network flooding (wrong concept)

Q: No, for example, when a resource is valid, all users will be notified (in fact, the phenomenon of the shocking herd effect has been explained...)

A: Let me give an example first, the waiting queue in the Linux kernel, the waiting nodes in the waiting queue have two states, one is mutually exclusive waiting, and the other is non-mutually exclusive waiting. If an event occurs, it will wake up all non-mutually exclusive waiting nodes in the corresponding waiting queue, and if it is a mutually exclusive waiting node, you can choose to wake up all nodes, or you can choose to wake up a specified node. There is also a good example in the Pthread thread library, pthread_cond_signal and pthread_cond_broadcast, signal only notifies one semaphore, and broadcast notifies all semaphores. But sometimes the ready event can only satisfy one user. If you choose to broadcast, all users will be notified, and then only one user can be satisfied in the end, and other users are still blocked, resulting in unnecessary performance waste.

Q: So how do you solve the shocking crowd?

A: ... (Wrote a pseudo-code, roughly locking, conditional judgment...)

effect of interruption

Q: What is the effect of interruption

A: ... (Interrupts analyzed from the CPU, what privilege levels, interrupt gates, trap gates, task gates, etc. have all been discussed)

Q: This is an interruption of your analysis from a very low-level and detailed aspect, but I want to understand it from a macro perspective

A: ... (language blocked)

Q: For example, task scheduling?

A: Oh, is there a time interruption? If there is no time interruption, the multitasking operating system cannot be scheduled in time, and malicious programs may occupy the processor and kill the operating system.

Q: It won't necessarily kill you. What about the batch operating system?

A: Yes, yes...

tcp connection closed

Q: Tell me about the process of tcp closing the connection

A: Four-way wave, let me draw a picture

Q: Good

A: Let me describe this process with socket (I talked about the packet sending situation and state changes after each function operation. It was said before that the closed party will change to CLOSE_WAIT state after receiving FIN. He said no, and later he found out that it was. ...)

A: .... (explaining), at this time, the status of the active closing party becomes TIME_WAIT... (interrupted, start to ask the next question)

TIME_WAIT

Q: If TIME_WAIT is used, can you explain its function?

A: ... (two roles)

Q: How to avoid it

A: ... (I talked about two, socket options and thread pools)

Q: Suppose there are many connections in TIME_WAIT in the system now, what will you do at this time?

A: There is a socket option for address reuse, we can reuse the addresses of these connections in the TIME_WAIT state, no problem

If the network delay is high, but no packet loss occurs, using tcp will reduce the throughput. How to solve it?

Q: Do you understand tcp sliding window?

A: I understand (I was interrupted when I was about to start the introduction)

Q: ok, what about tcp congestion control?

A: I know

Q: OK, assuming that the network delay is very high now, but no packet loss occurs, what do you think about the speed of tcp transmission at this time?

A: Not very good

Q: Then how would you solve it?

A: If the network delay is very high, but there is no packet loss in the network, the congestion control of tcp may perform fast retransmission to reduce the sending rate. Do you think the bottleneck lies in fast retransmission?

Q: Well, that is, I want to avoid congestion control

A: (Wow suddenly the problem is clear...) Encapsulate the udp protocol from the application layer or use the raw socket to directly encapsulate the ip datagram

Q: ...the network latency is not high enough to encapsulate ip datagrams

Ddos attack principle

Q: What is the principle of DDos attack?

A: emmm...listen has a queue that handles connection requests. After receiving the SYN from the anonymous IP, a record will be stored in the listen queue, but the queue capacity is limited. When there are too many malicious requests, the listen queue will be filled with these invalid connection requests. Then no more connection records can be installed, so other requests are rejected

Q: Well, that's roughly what it means

How to use stl standard library on shared memory

Q: Suppose I have opened up a piece of shared memory, and then I want to use the stl library on this piece of shared memory, what should I do?

A: Suppose two processes A and B use the same shared library. (Draw the memory layout of the process) The loader will automatically help them map the shared library to the shared memory. We only need to specify the shared library when linking Just link

Q: No, you misunderstood what I meant. For example, when I use a vector, I want all its elements to be in shared memory, and even newly added elements are allocated in shared memory.

A: emmm...Let me think about it...(Write out the vector template declaration, pointing to the template parameter Alloc of the vector), we can rewrite an allocator, divide the shared memory into it, and use the shared memory Implement a memory pool and let the allocator manage it

Q: Do you rewrite an allocator?

A: Yes

database engine

Q: Do you understand the database engine?

A: I don't know very well

Three important paradigms of database

Q: Do you know the three paradigms of database

A: Is the first, second and third normal form?

Q: Yes

A: ... (a brief introduction) Is there still time now? Would you like me to give you an example

Q: ... (looks at the time) The example is not needed

What are the devices at the network layer, data link layer, and transport layer?

Q: What are the devices at the data link layer?

A: The bridge is yes, the hub...emmm the hub is at the physical layer, and it's not clear, just know the bridge.

Q: What about the network layer?

A: Router

Q: What about the transport layer?

A: The transport layer, session layer and application layer in the OSI seven-layer model are all attributed to the application layer in the Tcp/Ip five-layer structure. Isn't there only software at this time?

Q: Yes, software is also a kind of equipment.

What are the network layer and transport layer protocols?

Q: What protocols are there in the network layer?

A: ip, icmp, and igmp are the three main ones. By the way, there is also a rip

Q: What about the transport layer?

A: For the transport layer, there are mainly two types of tcp and udp.

What are the addressing addresses used by the network layer, data link layer, and transport layer?

Q: What addressing does the network layer use?

A: ip address

Q: What about the data link layer?

A: The physical layer is mac...emmm...not the data link layer is mac

Q: What about the transport layer?

A: (write { ip: port } on paper) this

Q: Does the transport layer have an ip?

A: (circle the port) That's it...

memory allocation principle

Q: Introduce the principle of memory allocation

A: ... (Tell me about the memory of the heap (there is a chapter in "In-depth Understanding of Computer Systems"), and then carefully describe the specific implementation of the partner system)

The realization principle of polymorphism

Q: Tell me about the implementation of C++ polymorphism

A: ... (from the virtual table, virtual function table, virtual function table pointer to a specific introduction, and then introduces the change process of the virtual function table pointer in the process of construction and destruction, and then explains the language-level phenomenon from these changes. ...)

AVL tree, B+ tree, red-black tree

Q: Introduce balanced binary tree, B+ tree, red-black tree

A: The height difference between the two subtrees of each node of a balanced binary tree is less than 2, so it is also called a height-balanced tree. The red-black tree realizes that the height difference between the left and right subtrees of each node is less than 2 times according to the black height. Although the balance of the red-black tree is not as strict as that of the AVL tree, the research seems to show that the red-black tree has better performance and this degree of balance enough. The B+ tree is not very clear, but I know that it is used a lot in the database, and only its leaf nodes contain actual data, and other nodes only contain keys

gcc options

Q: What gcc options know

A: -O optimization option, -W to strengthen warnings... and staged compilation: -E precompile to generate .i files, -S precompile + compile to generate .s files, -c generate .o files, -o specifies Output file, -l specifies the link library, which is almost the most used

Q: Add debugging information

A: The simplest, for example, there is a pritnk for kernel debugging...

Q: No, no, I mean what option does gcc use to add debugging information to the program when compiling

A : -gstabs

Q: What about multi-threaded compilation?

A: -j (in retrospect now, I find that the -j option is an option of make, gcc does not support multi-threaded compilation...)

The difference between poll and epoll

Q: Do you understand poll and epoll?

A: Let’s analyze it from the kernel source code, eh, don’t you need to introduce select... Forget it, in fact, select is similar to poll, it reuses a lot of code, but the data structure for recording and monitoring events is different... (Introduced first select, and then talk about the difference with poll). For epoll, it seems that only Linux has it in Unix-like systems. epoll separates epoll instance creation, events addition, deletion, and events polling, so that epoll instances can be shared by all threads in the same process. Like poll, epoll uses linked list nodes to record and monitor events, but it has three linked list structures (ready linked list, auxiliary linked list, red-black tree). Speed ​​up access to the events node. After events are ready, they will be mounted into the ready list. When epoll_wait writes ready events from kernel space to user space, it will traverse the ready list. At the same time, new ready events may occur at this time, which are ready at this time. Events are no longer added to the ready list, but use the auxiliary list...

The difference between ET mode and LT mode in epoll

Q: Let’s talk about epoll’s ET mode and LT mode

A: In the epoll_wait call, epoll will traverse each events node in the ready queue, and then obtain the latest state revents of the event through the poll method of the file, and then delete the events node from the ready list. When revents contains the events we care about, the LT mode will also re-add the node to the ready queue, while the ET mode, which is the edge boundary mode, will not. What's the impact of this, emmm... let me give an example, let's say we listen to a pipe to read, and when the event is ready, we read only part of the content, and part of the content is not read. When we epoll_wait again, for LT mode, there are still nodes of this event in the ready queue, and get the status again, yes! It is still readable, so it is still not deleted from the ready queue, and then this event is returned; for the ET mode, there is no node for this event in the ready queue, so it will not be notified again. When will the event node in the LT mode be deleted? Suppose we have read all the contents of the pipeline during the first epoll_wait. The next time epoll_wait traverses to this node and retrieves its state, it has already been No longer ready, because the pipeline is empty, this time LT mode will not re-add this node to the ready queue.

Q: The respective application places of LT mode and ET mode

A: LT mode is slower, but safer, that is, if it is really ready, it will notify you again; while ET mode is faster, but it may cause event loss, which may cause the program to block forever. In order to take responsibility, LT reduces efficiency, while ET puts the responsibility on users for efficiency

last minute

Q: Okay, the interview is over. Are you still in the past two days?

A: Well, what will be the next arrangement?

Q: I will arrange a face-to-face interview for you right away, you should be able to receive the news soon

A: Well, okay, thank you

A: (pick up the bag from the ground and put it on his lap to get up) Rate me

Q: very good

A: Is it that simple?

Q: Well, that's pretty good...

A: Well...

Summary (feelings): The first interview is also the first interview. At the age of 6, I can't panic for the interview? I was very nervous when I was told to go to the interviewer's room when I received the interview notice, and I shouted several times in the elevator. At first, I was not in the state, but I adjusted it immediately. Overall, I felt that I played well, and I could almost answer the questions. The interviewer is also better, reminded me several times, and chatted and laughed with the interviewer. Most of the interview questions come from the personal skills of the resume, and there are very few projects.

Second face (director face)

Process: submit resume -> start interview -> end

Time required: about 20 min

Start the interview:

the first minute

Q: Tell us about what you have learned during your school days

A: Almost everything was self-taught during the school... (Then introduced what I have learned from the first semester of my freshman year to the second semester of my junior year, what I have done, what I am interested in)

What did you learn from the projects written on your resume

STL allocator

Q: Introduce the allocator

A: ... (starting from the SGI STL source code, the first and second level allocators are introduced, and the implementation of the memory pool is emphasized)

Coupling relationship between iterator and container

Q: Introduce the coupling relationship between iterators and containers

A: In SGI STL, only the container has a dependency on the iterator, and the iterator has no coupling relationship with the container. So, for example, after the vector is expanded, the iterator will be invalid, and dereferencing such an iterator may cause illegal access. But when VisualStudio used its C++ STL library CRT, if the container was expanded and then dereferenced their defunct iterators, an exception would be thrown. So I guess that in their implementation, the iterator must be associated with the container. Every time the iterator is operated, the validity of the iterator will be checked according to the container, and an exception will be thrown if it is invalid.

The role of Type traits

Q: What does type extraction do?

A: ... (I gave several examples from the STL design to illustrate its function, but it seems that it is not very clear)

Binary search tree and hash table

Q: ... (I gave a few examples of applications, the specific content is very vague)

database index

Q: The role of database indexes

A: Speed ​​up access

Q: What data structure is used to implement the index

A: ... (I heard what the keys are used to implement... Then I was speechless)

Q: Is it implemented with a hash table?

A: ... (I seem to be answering??? This question is a bit confusing after the question about the hash table)

database transaction

Q: An introduction to database transactions

A: ... (The database foundation is not very good, just briefly introduced the atomicity of this operation, and then he asked me how the implementation of the transaction is, I just talked about my personal guess...)

Write a simple FTP server

Q: I now want to write a simple web server that responds to the user's corresponding data, how to write

A: Can the FTP server work?

Q: The FTP server is just the FTP server...

A: ... (handwritten pseudocode)

Q: Don't write it out line by line

A: ... (stop writing) First create a server socket, then bind the address, listen to it, and then add the socket to the multiplexing listening list. When a connection arrives, we call accept on the socket, return a connected socket descriptor, and then find the file according to the file name transmitted by the user, read the file content and send it back to the user (interrupted)

Q: What to do with the server socket when reading a file

A: Create a thread after accepting. If you use a thread pool, take an idle thread from the pool, pass the connected file descriptor to the thread, and let the thread process the user request

Q: Does one thread handle one user request?

A: Yes

Design web page access cache data structure

Q: Suppose I want to cache the access records of the web server, how to implement this data structure

A: Use a queue, sort according to last visited, first in first out

Q: If you use a queue, how do you determine whether the cache is hit or not?

A: emmm...how do you judge whether it hits or not?

Q: key

A: Then I still use the queue, each element contains two parts of the key and the value, and the value is the access record. Then I use a red-black tree to save the key value, which is a pointer to the queue element

A: Actually, it is better to use a hash table, which is faster, but I generally prefer to use a red-black tree...

last minute

Q: Okay, let's face it here

A: ... (I can't believe that I only met for such a short time, it was really empty, very empty, very empty at that time)

A: Rate me

Q: Huh? (The interviewer was expressionless and cold throughout the whole process, maybe he was stunned by my question...)

A: Rate me

Q: This foundation is enough for an undergraduate degree, but there are still some deficiencies.

A: Database and network?

Q: Your database foundation is not very good

A: Okay, thank you. Are there any other arrangements?

Q: Go back and wait for the notice. I will let HR contact you as soon as possible. It should be fine tomorrow, and it will be a day or two at the latest.

Summary (feelings):

It took more than 50 minutes to wait for the number to be called. After being called, I came to the interviewer's room. At that time, there was still a girl who did not come out. At the time I thought it was two people facing me, then I knocked on the door and he told me to wait. I heard them talking about data structures and algorithms outside the door... I was panicking at the time, although I wasn't very scared, but I was a little worried about quickly solving the algorithm problems in this tense environment. The overall feeling in the afternoon was not very difficult, but the atmosphere was not very good, because the interviewer exuded a dreadful temperament that made me very cowardly, and every time I said a word, he hummed loudly (sometimes it made me very embarrassed), In the morning, it was ok occasionally... I thought that the two sides would tear up a lot of algorithms, but the result was not, it was a false alarm. In the end, he said that he was really scared when he came here, because the time was too short and too short... I thought it would not be so cold.

Then I took the initiative to ask him for the evaluation he wanted and said I was a scumbag, and "you go back and wait for the notice", all of which made me very cowardly. The interview status was still not updated at 0:00 that night, and it was not until I woke up at 3:00 in the morning that I found that the status had become an HR interview... The interview questions all came from the personal skills of the resume and project experience.

Three sides (HR side)

On the 17th, I got up at 3:00 a.m. and wrote one or two face-to-face scriptures. At 12:00 noon, I was still in bed and then received a call from HR to go to the hotel for an interview at 14:00. That day, I was in a bad mood and still very sleepy. During the HR interview in the afternoon, Miss HR would answer whatever she asked without any thought, and then revealed a lot of flaws in her words, and even showed some non-existent things. Dark side and flaws. The content of the question is roughly about learning methods, social interaction, future planning, academic qualifications, why not postgraduate entrance examination, why you come to WeChat business group (voluntarily fill in WXG, Shenzhen - do not obey the adjustment)... In fact, hr will also ask about the project... And she will check the resume carefully, such as whether there are typos, unscientific project time, etc. etc. When looking at other people's hr, they will ask about the household registration, whether they have a girlfriend, etc., but why not ask me if I have a girlfriend friend? ? ?

(Actually, I knew for a long time, but I didn't want to say it. How could she not have a girlfriend because I was so handsome (shy...)...Actually, I really don't have a girlfriend...)

Summary (feelings):

When I encountered hr pressure, I thought that I would definitely fail, and the interview status continued for two days in the "hr interview". Later, I took the initiative to ask the hr when the status might be updated. I told her that I might be cool, and she He asked me why I thought I would hang up, and then asked me to check the status... I thought the latest status would be "not suitable for this position", and after reading it, it was "completed all interviews", really happy!

Updated April 24

Received the offer call at 10:30 am on April 23rd, and the acceptance letter at 5:30 pm...

 

 

Author: call Xiaoding not Xiaodingding

This article comes from Niuke.com

——————————

Niuke.com (www.nowcoder.com)

- Real Questions for Written Exam of Internet Famous Enterprises

- On-campus job-hunting pen & face

- Programmer job placement information

- Programmer learning exchange community

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324848243&siteId=291194637