C++ Socket编程与多线程面试题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/177197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Interview Questions on Socket Programming and Multi-Threading
提问by Santhosh
Please anybody can tell me the questions, that can be asked in an interview for below topics
请任何人都可以告诉我可以在面试中针对以下主题提出的问题
- Socket Programming
- Multi-Threading
- 套接字编程
- 多线程
An advance thanks goes to everybody who provide their time
预先感谢所有提供时间的人
回答by Rob?
As a hiring manager, my favorite networking question to ask was this:
作为招聘经理,我最喜欢问的网络问题是:
Imagine a user sitting at an Ethernet-connected PC. He has a browser open. He types "www.google.com" in the address bar and hits enter.
Now tell me what the first packet to appear on the Ethernet is.
想象一个用户坐在连接以太网的 PC 前。他打开了浏览器。他在地址栏中输入“www.google.com”并按回车键。
现在告诉我出现在以太网上的第一个数据包是什么。
Possible answers (of varying correctness) include:
可能的答案(不同的正确性)包括:
- I don't know.
- An HTTP request packet.
- A TCP syn packet.
- A DNS request packet.
- An ARP packet.
- It depends.
- 我不知道。
- HTTP 请求数据包。
- TCP 同步数据包。
- DNS 请求数据包。
- 一个 ARP 数据包。
- 这取决于。
Each of the answers reveals something about the person's understanding of networking in general, and IP and TCP in particular. The subsequent discussion can reveal volumes about their understanding. (Assuming, of course, that the questioner has some expertise in this area).
每个答案都揭示了人们对网络的总体理解,尤其是 IP 和 TCP。随后的讨论可以揭示有关他们理解的大量内容。(当然,假设提问者在这方面有一定的专业知识)。
回答by arul
Socket Programming
套接字编程
- Difference between UDP and TCP.
- Difference between asynchronous and synchronous sockets.
- What is a packet.
- How'd you determine if packet didn't arrive malformed.
- How'd you determine where one packet ends and where another one starts.
- What is a port.
- UDP 和 TCP 的区别。
- 异步套接字和同步套接字的区别。
- 什么是包。
- 您如何确定数据包是否未格式错误。
- 您如何确定一个数据包的结束位置以及另一个数据包的开始位置。
- 什么是端口。
Multi-Threading
多线程
- What synchronization primitives do you know, tell difference between them.
- What is a deadlock and what is a livelock.
- What is a race condition.
- What does the term 'lock-free' mean.
- What is the best way to terminate a thread.
- Why you shouldn't use TerminateThread-esque functions.
- 你知道哪些同步原语,说出它们之间的区别。
- 什么是死锁,什么是活锁。
- 什么是竞态条件。
- 术语“无锁”是什么意思。
- 终止线程的最佳方法是什么。
- 为什么不应该使用 TerminateThread 风格的函数。
回答by terson
A couple of example questions:
几个示例问题:
- Asynchronous I/O, one approach is to ask a question where different clients may query the server and may result in race conditions if implemented via multiple threads (e.g. caching of results). If the interviewee goes for multiple threads, bring up the race conditions and see whether they mention asynchronous I/O as an option.
- What is the difference between dead-lock and live-lock
- Prototype a web server
- Prototype a web client
- What are ephemeral ports; alternatively describe a load stress application that hits a server with 1000s of requests per second but after several seconds stops making requests to the server; after 2-4 minutes the application again starts hitting the server with 1000s of requests.
- Write a thread-safe producer/consumer buffer that can be accessed by one or more producer/consumers
- What is the difference between client/server and p2p
- This is more networking, but it is helpful to know what happens underneath the socket calls: describe the TCP 3-way handshake
- What is nagle's algorithm? When is it desirable? How would you turn this off?
- Linux variant: when writing a daemon what are the basic building blocks (i.e. forking a child and killing the parent, closing stdin/stdout/stderr etc.)
- Windows variant: when writing a windows service what are the basic building blocks.
- Design a protocol for communicating between a client and a server for sending audio/video. How do you extend it for the next latest/greatest feature.
- How does TCP windows work and what can I do to optimize performance for an application that performs lots of large reads across continents.
- 异步 I/O,一种方法是提出一个问题,其中不同的客户端可能会查询服务器,如果通过多个线程(例如,结果缓存)实现,可能会导致竞争条件。如果受访者选择多线程,请提出竞争条件,看看他们是否提到异步 I/O 作为选项。
- 死锁和活锁有什么区别
- 原型网络服务器
- 原型 Web 客户端
- 什么是临时端口;或者描述一个负载压力应用程序,它以每秒 1000 次的请求命中服务器,但在几秒钟后停止向服务器发出请求;2-4 分钟后,应用程序再次开始以 1000 次请求访问服务器。
- 编写一个线程安全的生产者/消费者缓冲区,可以被一个或多个生产者/消费者访问
- 客户端/服务器和p2p有什么区别
- 这是更多的网络,但了解套接字调用下面发生的事情会很有帮助:描述 TCP 3 次握手
- 什么是纳格尔算法?什么时候是可取的?你会如何关闭它?
- Linux 变体:在编写守护进程时,基本构建块是什么(即分叉子进程并杀死父进程,关闭 stdin/stdout/stderr 等)
- Windows 变体:在编写 Windows 服务时,基本构建块是什么。
- 设计用于在客户端和服务器之间进行通信以发送音频/视频的协议。您如何为下一个最新/最伟大的功能扩展它。
- TCP 窗口是如何工作的,我可以做些什么来优化跨大洲执行大量大型读取的应用程序的性能。
回答by Eclipse
回答by Andy Lester
Are you asking because you've been dragged in to interview someone who will be on your team? Ask questions that are based in real-life problems you've had to face in your day-to-day operations. Think of the last bug you had related to socket programming, and turn it into an interview question.
你问是因为你被拖去面试将在你团队中的人吗?根据您在日常运营中不得不面对的现实生活问题提出问题。想想你最后一个与套接字编程相关的错误,把它变成一个面试问题。
Theory is nice, but you want to know that the person joining the team has experience in the trenches.
理论很好,但你想知道加入团队的人有战壕经验。
回答by Jobi Joy
- Why does a typical socket program need multi threading
- How do you talk to bunch of different network connections at once,from same process/thread? Hint:Asynchronous Socket
- Explain how Internet datatransfer works? or Explain how a webserver works? answer it based on socket programming concepts , Hint TCP Http etc..
- 为什么典型的socket程序需要多线程
- 你如何从同一进程/线程一次与一堆不同的网络连接交谈?提示:异步套接字
- 解释 Internet 数据传输的工作原理?或解释网络服务器的工作原理?根据套接字编程概念、提示TCP Http 等回答它。
回答by jxh
Socket questions
套接字问题
- What is a socket?
- What are the differences between
accept
andconnect
? - What are the differences between
close
andshutdown
? - How would you
connect
towww.google.com
asynchronously?
- 什么是插座?
accept
和之间有什么区别connect
?close
和之间有什么区别shutdown
?- 你会如何
connect
来www.google.com
异步?
Multi-threading questions
多线程问题
- What is a thread and how is it different from a process?
- When might you choose to use threads on a single CPU system?
- How would you measure the context switch overhead between threads?
- How would you make a MT-safe hash table, while allowing for maximal concurrency?
- 什么是线程,它与进程有什么不同?
- 您什么时候会选择在单 CPU 系统上使用线程?
- 您将如何衡量线程之间的上下文切换开销?
- 您将如何制作一个 MT 安全的哈希表,同时允许最大并发?
回答by Zelter Ady
- Name some advantages and disadvantages of Java Sockets.
- What is the difference between URL instance and URLConnection instance?
- How do I make a connection to URL?
- What Is a Socket in Java Networking and RMI?
- What information is needed to create a TCP Socket?
- What are the two important TCP Socket classes?
- When MalformedURLException and UnknownHostException throws?
- What does RMI stand for?
- What is RMI?
- What is the difference between the File and RandomAccessFile classes?
- What interface must an object implement before it can be written to a stream as an object?
- Explain Look for Local Ports
- What are the two important TCP Socket classes?
- 说出 Java Sockets 的一些优点和缺点。
- URL 实例和 URLConnection 实例有什么区别?
- 如何连接到 URL?
- Java 网络和 RMI 中的套接字是什么?
- 创建 TCP Socket 需要哪些信息?
- 两个重要的 TCP Socket 类是什么?
- 当 MalformedURLException 和 UnknownHostException 抛出时?
- RMI 代表什么?
- 什么是RMI?
- File 和 RandomAccessFile 类之间有什么区别?
- 对象在作为对象写入流之前必须实现什么接口?
- 解释查找本地端口
- 两个重要的 TCP Socket 类是什么?