tags : Systems, Operating Systems, Processes

We can make two processes communicate with each other using IPC.

Shared memory (Indirect)

  • One process creates an area in memory for others to access
  • Fast, no syscalls but does need some kind of synchronization.

Message Passing (Direct)

  • Shared memory created in Kernel
  • syscalls such as send, recieve etc are involved.
  • Pipes make use of message passing. (unidirectional)
  • See Message Passing

Signals

  • Asynchronous, unidirectional communication between processes.
  • Process receives a signal
    • Processes the signal immediately
    • Without finishing the currently running instruction
  • We can list all signals in the system with kill -l and man 7 signal

Relationship w Interrupts

  • The kernel may pass an interrupt as a signal to processes

Signal Handlers

  • Signal handler executes in userspace.

Traps

  • So signals are things that one process can send to another
  • Steps
    • A sends signal to B via a syscall
    • Kernel intercepts the signal, checks if A can send the signal to B or no and goes on or drops based on that.
    • If signal is SIGSTOP/SIGKILL it’ll send the signal regardless if B is blocking or not.
    • Kernel sends the signal to B if B is not blocking the signal.
      • Kernel sets a trap on the thread(B); adds it to the “pending signal set”
      • Next time the thread(B) is scheduled to run, B handles the signal instead of processing itself.
      • This means, if the context switch of B never happens, signal never will get processed.
    • When handing the signal, B has few options
      • Ignore the signal
      • Let the defult thing happen
      • Use a signal handler