Linux#
Linux is a kernel, which is a foundational element of a computer operating system. It is often described as an operating system in itself, particularly in comparisons to Mac and Windows, however operating systems will typically have a collection of ‘user space’ applications and tools in addition to a kernel.
There are many operating systems that use Linux as a kernel, which are often known as Linux distributions or ‘distros’. Given the important role that the GNU project user-space tooling played or plays in some Linux distributions they (for example Debian) are sometimes referred to as GNU/Linux.
Linux is an open-source derivative of the UNIX family of operating systems, inherting many of their behaviours and interfaces. Some, but not all, of its interfaces follow the Portable Operating System Interface (POSIX) specification.
Kernels#
Operating systems are often divided into two (or more) notional ‘spaces’. There is a ‘kernel space’ in which software interacts directly with hardware via drivers and ‘user space’ in which user applications and tooling run. This division allows for controlled allocation of resources, such as memory or CPU, to user applications and prevents applications from interfering with one another in general.
Kernels present an Application Programming Interface (API) to user space applications to query, request and modify system resources, in what is known as a ‘system call’. The Linux kernel has two primary methods of exposing its API. One is via special filesystems, in \sys
(and no longer recommended \proc
) and \dev
. Reading specific files in these filesystems allow the status of system resources to be queried. Some files can also be written to, to change the state of a resource. An interface to the kernel in the c
language is also available, which is usually consumed by a wrapper in the GNU C Library glibc
.
User Space#
The user-space in Linux distros typically has a heavy focus on the ‘shell’ or terminal as a means of user interaction, rather than graphical user interfaces as per other operating systems. That said, Linux distros have healthy support for graphical applications of which there are many.
A Linux distribution is usually a specific version of the kernel, which may be patched or configured according to the goals of the distro maintainers, a package manager and a repository of packages or applications that can be installed and work in a compatible way.
Linux is often used in server environments where a graphical display is not needed nor available. If a graphical display is needed then this is usually facilitated by a ‘desktop environment’ such as GNOME
or KDE
based on X11
or Wayland
display protocols and libraries.
Filesystem#
Given its effective use as an API to the kernel the filesystem on Linux plays a particularly important role, relative to other operating systems. Some particularly important filesystem locations are:
/dev
: This directory has files representing hardward devices (real or virtual) attached to the system. You can query and manipulate devices through their file entries here./proc
: This directory allows quering and (some) manipulation of kernel resources - including hardware by proxy. The/sys
directory is an attempt to ‘clean it up’./sys
: This directory has similar functionality to/proc
but has a cleaner structure.
Process Scheduling#
Process scheduling is related to the allocation of system resources, such as the CPU or GPU to running processes or applications.
This section collects some related tools and commands.
Taskset - System command to set or retrieve a process’ CPU affinity. The
sched_setaffinity
Linux system call is similar.nice (and related
renice
) is a program which sets the priority of a process in a scheduler. Low values related to a higher priority process.cgroups or ‘control groups’ are Linux kernel feature for controlling groups of processes, which can include access to system resources.
cpulimit
is a program to impose a limit on the cpu usage of a processes.
Further Reading#
ICHEC Intro To Linux - Stale (2 YO)
hwloc Library for obtaining information about the topology of the system resources.