Fundamentals 24 min read

Master Network & OS Fundamentals for Interviews: Handshakes, Protocols, and More

This comprehensive guide reviews essential network and operating system concepts for technical interviews, covering TCP three‑way handshake, four‑way termination, OSI/TCP‑IP models, common protocols, socket communication, process vs thread, IPC mechanisms, memory management, page‑replacement algorithms, and HTTP/HTTPS differences.

Alibaba Cloud Developer
Alibaba Cloud Developer
Alibaba Cloud Developer
Master Network & OS Fundamentals for Interviews: Handshakes, Protocols, and More

Network Fundamentals

TCP three‑way handshake:

Client sends SYN packet – client enters syn_sent state.

Server replies with SYN/ACK packet – server enters syn_rcvd state.

Client sends ACK packet – server moves to Established state.

Why three handshakes? To establish a reliable communication channel so both sides can send and receive data.

Why not two? Two handshakes cannot confirm both initial sequence numbers, leading to potential duplicate connections and unreliable data transfer.

TCP four‑way termination

Client sends FIN – client enters FIN‑WAIT‑1 .

Server acknowledges FIN – server enters CLOSE‑WAIT .

Server sends its own FIN – client enters FIN‑WAIT‑2 .

Client acknowledges server FIN – client enters TIME‑WAIT .

TIME‑WAIT ensures all packets are properly discarded and prevents old duplicate packets from interfering with new connections.

Check TIME‑WAIT connections with:

netstat -an | grep TIME_WAIT | wc -l

OSI and TCP/IP models

OSI 7 layers: Physical, Data Link, Network, Transport, Session, Presentation, Application.

TCP/IP 5 layers: Physical, Data Link, Network, Transport, Application.

Common network services by layer

Application: HTTP, SMTP, DNS, FTP

Transport: TCP, UDP

Network: ICMP, IP, routers, firewalls

Data Link: NIC, bridges, switches

Physical: repeaters, hubs

TCP vs UDP

UDP‑based protocols: RIP, DNS, SNMP

TCP‑based protocols: HTTP, FTP, SMTP

TCP sliding window and congestion control

TCP splits application data, numbers packets, adds checksum, and uses flow and congestion control to guarantee reliable transmission.

Congestion control prevents network overload by adjusting a congestion window using algorithms such as slow start and congestion avoidance.

TCP packet format

Key fields:

Source and destination ports – identify the communicating processes.

Sequence number – marks the first byte of data in the segment; initial sequence number (ISN) is chosen during the SYN.

Acknowledgment number – the next expected byte, valid only when ACK flag is set.

Header length – size of the TCP header in 32‑bit words (minimum 5, maximum 15).

Flags – URG, ACK, PSH, RST, SYN, FIN.

Window size – number of bytes the receiver is willing to accept.

Checksum – covers header and data for error detection.

Urgent pointer – valid only when URG flag is set.

Options – e.g., Maximum Segment Size (MSS).

UDP packet format

Source and destination ports.

Length – total length of header plus data (minimum 8 bytes).

Checksum – optional error‑checking covering header and data.

IP packet format

Version (4 for IPv4).

Header length – number of 32‑bit words.

Type of Service – priority, delay, throughput, reliability.

Total length – entire packet size in bytes.

Identification – unique ID for fragmentation.

TTL – maximum hops before discarding.

Header checksum – verifies header integrity.

Ethernet frame format

Destination MAC address.

Source MAC address.

Payload – 46 to 1500 bytes of data.

Operating System Fundamentals

Process vs Thread

Process: smallest unit of resource allocation; can contain multiple threads; has its own memory space.

Thread: smallest unit of scheduling; shares process memory (heap, static area) but has its own stack.

Coroutine: lightweight execution unit within a thread.

Inter‑process Communication (IPC)

Pipe – FIFO, half‑duplex; anonymous for related processes, named for unrelated.

Signal – asynchronous notification using kill command.

Message queue – stores structured messages, overcoming pipe limitations.

Shared memory – fastest IPC; requires synchronization (e.g., semaphores).

Semaphore – counting lock for mutual exclusion.

Socket – endpoint for network communication.

User mode vs Kernel mode

User mode: limited memory access, runs application code.

Kernel mode: full hardware access, runs OS code.

Transitions occur via system calls, exceptions, or hardware interrupts.

Memory management

Segmentation – variable‑size segments (code, data, stack).

Paging – fixed‑size pages and frames; eliminates external fragmentation.

Segmented paging – combines both techniques.

Page‑replacement algorithms

FIFO – simple but may suffer poor performance.

LRU – evicts the least recently used page; exploits locality.

OPT – theoretical optimal algorithm that removes the page not needed for the longest future interval.

/**
 * LRU cache implementation using LinkedHashMap
 */
public class LRUCache {
    private LinkedHashMap<Integer,Integer> cache;
    private int capacity; // capacity size

    public LRUCache(int capacity) {
        cache = new LinkedHashMap<>(capacity);
        this.capacity = capacity;
    }

    public int get(int key) {
        if (!cache.containsKey(key)) {
            return -1;
        }
        int res = cache.get(key);
        cache.remove(key);   // move to end
        cache.put(key, res);
        return res;
    }

    public void put(int key, int value) {
        if (cache.containsKey(key)) {
            cache.remove(key);
        }
        if (capacity == cache.size()) {
            // remove eldest entry
            Iterator<Integer> it = cache.keySet().iterator();
            cache.remove(it.next());
        }
        cache.put(key, value);
    }
}

Deadlock

Four necessary conditions: mutual exclusion, hold‑and‑wait, no preemption, circular wait.

Resolution strategies break at least one condition, e.g., using timeout, lock ordering, or preemptive resource release.

Summary

For interview preparation, master TCP handshake/termination, OSI/TCP‑IP layers, common protocols, sliding window, congestion control, and HTTP/HTTPS differences. Understand process vs thread, IPC mechanisms, memory management, and page‑replacement algorithms, especially LRU, which frequently appears in exams.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

networkTCPProtocolsinterviewOperating System
Alibaba Cloud Developer
Written by

Alibaba Cloud Developer

Alibaba's official tech channel, featuring all of its technology innovations.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.