Interview Questions on Socket Programming and Multi-Threading [closed] Interview Questions on Socket Programming and Multi-Threading [closed] multithreading multithreading

Interview Questions on Socket Programming and Multi-Threading [closed]


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.

Possible answers (of varying correctness) include:

  • I don't know.
  • An HTTP requestpacket.
  • A TCP syn packet.
  • A DNSrequest packet.
  • An ARP packet.
  • It depends.

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).


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.

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.


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.