Difference between revisions of "Operating System Organization"

From Soma-notes
Jump to navigation Jump to search
Line 24: Line 24:


Each process that is currently running on the system gets its own directory in /proc, with the process ID (pid) as the directory name. For example for process with pid 2, there exists "/proc/2/" which contains more information about that process.  
Each process that is currently running on the system gets its own directory in /proc, with the process ID (pid) as the directory name. For example for process with pid 2, there exists "/proc/2/" which contains more information about that process.  
=====/dev=====


The "/dev" directory actually exists on the file system and contains entries for devices (called nodes). For example, the first hard drive on the system might reside in "/dev/hda/". Each device entry has a major node number and a minor node number. For example, the hard drive specified by "/dev/hda" might have major node number "3" and minor node number "0". At first the node numbers were pre-defined and there could be no more than 255 of them. These major/minor node numbers are used to link the specific device types into the kernel. These nodes existed in "/dev" even if the devices were not connected to the system.
The "/dev" directory actually exists on the file system and contains entries for devices (called nodes). For example, the first hard drive on the system might reside in "/dev/hda/". Each device entry has a major node number and a minor node number. For example, the hard drive specified by "/dev/hda" might have major node number "3" and minor node number "0". At first the node numbers were pre-defined and there could be no more than 255 of them. These major/minor node numbers are used to link the specific device types into the kernel. These nodes existed in "/dev" even if the devices were not connected to the system.


This was eventually replaced with a new system called "devfs" (device file system), which was a pseudo-file system similar to /proc. Devfs is implemented in the kernel and knows about the currently available hardware. Some problems still existed with this system: it was implemented in the kernel, and thus a change to hardware required an update to the kernel; and the major and minor node numbers were still fixed in the kernel. It would be nice to dynamically reassign major nodes to unknown devices that are actually present on the system.  
=====devfs=====
 
This was eventually replaced with a new system called "devfs" (device file system), which was a pseudo-file system similar to /proc. Devfs is implemented in the kernel and knows about the currently available hardware. Some problems still existed with this system: it was implemented in the kernel, and thus a change to hardware required an update to the kernel; and the major and minor node numbers were still fixed in the kernel. It would be nice to dynamically reassign major nodes to unknown devices that are actually present on the system. Devfs also prevented the renaming of nodes in /dev. For example, previously one could rename /dev/hda to /dev/cdrom, but it would still actually point at hard-drive a. This behaviour was prevented in devfs.
 
=====udev=====
 
Another problem existed with hot-pluggable devices (such as USB devices). Minor node numbers were assigned by the kernel in the order by which they were discovered. Devices might have different node numbers after a reboot. Also no notifications occur when a device is connected or disconnected from the system.
 
Devfs has since been replaced by a new system named "udev", which was implemented in the user space, not the kernel space. The ability to rename nodes in /dev was enabled again by udev. The issue regarding hot-pluggable devices was addressed by permitting minor node numbers to be dynamically assigned. udev also notifies applications when hardware is connected or disconnected. Network cards are a special case - the kernel knows about network protocols, so network cards must be accessed using a different interface.
 
=====Other files, pipes and sockets=====
 
An example call for opening the CD-ROM may look something like:
<pre>
handle = open(/dev/cdrom, ...)
</pre>
This is call to the kernel which will use the cd-rom devices drivers to read from the disc.
 
Pipes and sockets both operate as files and support the basic operations
* open
* read
* write
* close
 
Pipes are used for inter-process communication. Each process can open one end of the pipe, and then they can read or write to it.
 
Sockets are used in a similar manner to communicate over a network.


Devfs has since been replaced by a new system named "udev"
====Kernel Development====

Revision as of 23:11, 23 September 2007

Operating System Organization

Device Management

How do kernels communicate with devices such as a network card? How do drivers for such devices fit into the kernel? We need a mechanism to allow applications to communicate with the devices. Most kernels use a form of message passing, often using a registration system. For example, a network card device driver would register itself with the kernel and identify that it is in fact a network card (as opposed to say, a mouse). MS DOS used interrupt handlers instead.

Glenn's talk focused mostly on the how the Linux Kernel works.

File Abstraction

In Linux there exists a "/proc" directory which contains special information. This directory does not actually exist on disk. When the kernel receives a request to read a file in one of these directories, it retrieves system information and serves it up as a file. For example, executing more /proc/cupinfo gives:

$ more /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family    : 6
model         : 13
model name    : Intel(R) Pentium(R) M processor 1.73GHz
stepping  : 8
cpu MHz       : 798.000
cache size    : 2048 KB
...

Each process that is currently running on the system gets its own directory in /proc, with the process ID (pid) as the directory name. For example for process with pid 2, there exists "/proc/2/" which contains more information about that process.

/dev

The "/dev" directory actually exists on the file system and contains entries for devices (called nodes). For example, the first hard drive on the system might reside in "/dev/hda/". Each device entry has a major node number and a minor node number. For example, the hard drive specified by "/dev/hda" might have major node number "3" and minor node number "0". At first the node numbers were pre-defined and there could be no more than 255 of them. These major/minor node numbers are used to link the specific device types into the kernel. These nodes existed in "/dev" even if the devices were not connected to the system.

devfs

This was eventually replaced with a new system called "devfs" (device file system), which was a pseudo-file system similar to /proc. Devfs is implemented in the kernel and knows about the currently available hardware. Some problems still existed with this system: it was implemented in the kernel, and thus a change to hardware required an update to the kernel; and the major and minor node numbers were still fixed in the kernel. It would be nice to dynamically reassign major nodes to unknown devices that are actually present on the system. Devfs also prevented the renaming of nodes in /dev. For example, previously one could rename /dev/hda to /dev/cdrom, but it would still actually point at hard-drive a. This behaviour was prevented in devfs.

udev

Another problem existed with hot-pluggable devices (such as USB devices). Minor node numbers were assigned by the kernel in the order by which they were discovered. Devices might have different node numbers after a reboot. Also no notifications occur when a device is connected or disconnected from the system.

Devfs has since been replaced by a new system named "udev", which was implemented in the user space, not the kernel space. The ability to rename nodes in /dev was enabled again by udev. The issue regarding hot-pluggable devices was addressed by permitting minor node numbers to be dynamically assigned. udev also notifies applications when hardware is connected or disconnected. Network cards are a special case - the kernel knows about network protocols, so network cards must be accessed using a different interface.

Other files, pipes and sockets

An example call for opening the CD-ROM may look something like:

handle = open(/dev/cdrom, ...)

This is call to the kernel which will use the cd-rom devices drivers to read from the disc.

Pipes and sockets both operate as files and support the basic operations

  • open
  • read
  • write
  • close

Pipes are used for inter-process communication. Each process can open one end of the pipe, and then they can read or write to it.

Sockets are used in a similar manner to communicate over a network.

Kernel Development