Post

Blocking I/O, Non-Blocking I/O

I/O can take place in kernel level
process, thread needs to request for I/O in kernel

βœ… Blocking I/O

block user process during I/O

  1. Process(Thread) requests I/O in kernel
  2. When kernel is done, return value to process
  • when I/O is in process, user process(thread) has to wait
  • waste resource

    • I/O does not use CPU
  • If various client connecting server is made in blocking
    • if there is I/O
    • cannot stop client process
    • need to create each process thread for each client
    • if a lot of clients connect at once
    • πŸ‘ŽπŸ» context switching between thread

βœ… Non-Blocking I/O

does not block user process during I/O

  1. User process calls recvfrom method
    tell kernel process needs data from socket
  2. Kernel cannot return recvfrom immediately, so returns EWOULDBLOCK
  3. User process does its work
  4. if there is data on recvfrom for user, recives data from Buffer

    recvfrom is on the memory of kernel, thus faster retrival of data

  5. recvfrom will copy the data, and return to user
This post is licensed under CC BY 4.0 by the author.