Pipe and Signal

Operation System

Pipe and signal are two common technology to do processes communication. And Linux 0.11 has supported both of them. Here are the brief introduction to the implemention of the them.

Pipe

Pipe can only be used between processes with kinship (father and child processes). In Linux 0.11, pipe is a memory page shared by two processes. When the father process creates an pipe, it equals to opening a file twice, and getting two file descriptors. One is for reading and the other is for writing. But the inode used here is not pointing to a virtual disk or disk. This is a pipe inode. Even though it is an inode, but it has totally different meaning. Its i_size points to an memory page which means a 4KB buffer, i_zone[0] and i_zone[1] means the head and tail of the buffer.

Reading/writing operation is done by move the head/tail pointer and then read/write data. When the buffer is full or empty, the current process will fall asleep.

Signal

Linux 0.11 supports 32 kinds of signals and in the process task structure, there is a structure array sigaction[32], corresponding to the signal and its functions (handle and recover). When we call the system call signal(), the program will register the functions for the signal.

Linux 0.11 sends signals by calling function kill(). This function will sent signal to a process or process group (not just kill them). Sending signal means set the corresponding bit of the process. During the scheduling, the kernel will check all the signals and set the processes with at least one signal into Ready status. When the processes in Ready status begin to execute and timing out happens or system call is called, it will execute the signal handle function. So the handle function is executed in the kernel. After executing the handle function, the system will call the
sa_restorer function. This function does not exist in the kernel code, and is not written by the programmer. It is provided by the libc library and the compiler will integrate it into the program. The sa_restorer function will recover the environment of the process.

Post Directory

Directory

  1. Pipe
  2. Signal