Unix
Unix
Unix is the first operating system built upon a high-level language (obviously a
high-level language at that time), C. If the developers at Bell Labs had thought
to use something else to create Unix, then C might not have come into existence.
While C wasn’t exclusively created for Unix, its development was significantly
intertwined with the creation and success of the Unix operating system.
Multics OS
Before Unix, there was another operating system that focused on the same
objectives of being fully functional and secure. Multics OS, even Bell Labs con-
tributed to this project. MIT and General Electric were two other contributors
to this project.
Almost every organization and university was using Multics at that time. Even
now, its ideas are inherited indirectly by every operating system from UNIX.
Bell Labs eventually moved away from the Multics project due to its complex
design and other factors. This decision ultimately paved the way for the devel-
opment of Unix, which has had a profound impact on the computing world.
Programming Language C
0.0.2 Inspiration for C
Bell Labs initially wrote Unix in assembly. However, as part of the Multics
project, they were introduced to BCPL as a compiler design language. They
1
saw that Multics was not built upon assembly but was using Pl-1. While BCPL
was not a central language used in the Multics project, it did influence the
developers at Bell Labs, including Dennis Ritchie, who went on to create the C
programming language. C, in turn, played a significant role in the development
of the Unix operating system.
BCPL needed a few modifications to work with minicomputers. This simplified
version of BCPL is called ’B’. It improved and was able to write programs for
minicomputers as well. Eventually, C was introduced as a perfect language with
versatility and portability.
0.0.4 Limitations of B
B operated on words.
B wasn’t aware of different types.
B could not work on multiple byte-oriented algorithms.
B was not able to perform floating-point operations.
2
3. Low-Level Accessibility: Unlike some modern languages that create an
additional layer of abstraction, C allows programmers to access low-level
implementation details without imposing barriers.
Unix Architecture
0.0.6 Philosophy
While Multics was ambitious in its goals, including a secure and fully func-
tional time-sharing operating system, hierarchical file system, virtual memory,
dynamic linking, and more, these goals made the Multics project complex. It
was being developed simultaneously by multiple organizations, making it even
more intricate.
On the other hand, Unix kept it simple. It primarily focused on providing a
minimal operating system with simplicity and practicality. It believed in making
programs for specific tasks, which, in programming terminology, is referred to as
modularity. Over time, Unix incorporated ideas and concepts from the Multics
project, adapting them to fit its simpler and more practical philosophy.
The following are the philosophies that C adapts:
1. Unix primarily focuses on programmers, not end-users.
2. Unix is composed of small, simpler programs.
3. Unix is text-oriented; even every single configuration is a text file.
4. Complex programs can be made using chains of small programs. These
programs are termed transformer programs.
5. One program should accept the output of another program and provide
output.
6. It does not provide perfect programs, but it does provide simple programs
to perform the same task more efficiently.
7. Unix programs can be used in other Unix-based OS.
The key concept of C philosophy is modularity, and all these modular programs
as part of C are written in C, which makes them closely related.
C was designed to support modular programming, which involves breaking down
a complex problem into smaller, manageable modules or functions. These mod-
ules can be developed, tested, and maintained independently, contributing to
code reusability and easier collaboration.
C’s modularity and the modular design of the Unix operating system contributed
to their success and their close relationship. Many of the core utilities and
system components of Unix were written in C, taking advantage of its modular
programming capabilities.
3
0.0.7 Unix Onion
The onion architecture refers to the layered structure of Unix. This architecture
separates the operating system into different layers, with each layer building
upon the functionalities provided by the lower layers. This modular design made
Unix more manageable, maintainable, and extensible. It’s fascinating how this
architectural choice has stood the test of time and remains a fundamental aspect
of Unix’s internal structure.
Each layer is a wrapper for the inner layer. Each layer provides an abstraction
for using hardware without being dependent on the architecture. The innermost
core of this model is hardware. The kernel provides a layer upon hardware and
an interface to work with system calls. The kernel layer is the closest among
all others. It has the highest privileges to use hardware. This is why we need
another layer; we don’t want to expose such critical privileges directly to user
space.
The layer implemented over the kernel is the shell. It provides several small
modular programs, each designed for a specific purpose, and these are also writ-
ten in C. It contains system libraries as well as their implementation functions.
The functions they contain are defined by the Simple Unix Specification (SUS),
making them Unix-compliant Operating Systems.
Lastly, there are user applications that are built using libraries provided by the
shell instead of making direct system calls to the kernel.
4
2. Header Interfaces: It contains declarations (APIs) for these functions.
There are 82 header files for the standard SUS.
3. Utility Interfaces: It consists of 160+ programs written in C for small
specific tasks. They implement the above two interfaces for their func-
tionality.
4. Scripting Language: It provides support to make shell scripts to automate
tasks using Utility programs.
5. Xcurses Interfaces: It provides a simple graphical interface in the command-
line interface without using any graphical engine.
Points to Be Noted:
System Interfaces and header interfaces together make up the C standard
library (libc).
Applications made for Unix-compliant operating systems can be ported
to another Unix-compliant OS, but it can’t be guaranteed to work on
Unix-like operating systems.
The user application’s request will be passed down to the kernel using
interfaces provided by the shell ring.
0.0.10 Kernel
Kernel space is an abstraction over hardware. It represents a layer between
hardware and processes, preventing direct hardware access. Kernel images are
loaded by the bootloader, initializing a kernel process in main memory. This
kernel process interacts with actual physical addresses, whereas user processes
work with virtual addresses corresponding to physical addresses.
Different abstracted components are created within the kernel process:
5
Figure 1: User interacting with hardware
6
5. Inter-Process Communications: Processes share data through sock-
ets, pipes, or shared memory.
6. Device Management: Apart from CPU and memory, the kernel man-
ages hardware using an abstraction layer. Real and virtual devices are
both handled.
0.0.11 Hardware
Linux provides abstracted interaction with hardware. Hardware attached to
the system can be categorized as mandatory and peripheral hardware. Linux
only needs mandatory hardware; peripherals don’t halt Linux from running.
Mandatory hardware, CPU, and memory are used by the scheduler and memory
management unit, respectively. Besides that, all peripheral hardware can be
found as devices in /dev.