Operating Systems#
This Chapter covers the primary operating systems that we work with, namely Mac, Linux and to a lesser extent Windows.
In particular it covers working with the system shell and shell-based utilities, covering operating system specifics as needed.
Both Mac and Linux derive from the Unix family of operating systems, the former via the Berkeley Software Distribution. There are many similarities between these systems when working in the shell - in particular due to their close ties to the Portable Operating System Interface (POSIX) specification. Strictly, Linux is a kernel rather than full Operating System, with historically many user-space tools provided by the GNU (GNU’s not Unix) system. Some distributions of the Linux kernel and user-space tools refer to themselves as GNU/Linux to reflect this.
While Windows is also largely POSIX compliant its shell environments behave quite differently, developing from Disk Operating System (DOS) commands and more recently via the PowerShell. Thus, extra steps are aften needed to add Windows support to scripts and code that support Mac and Linux.
There are many distributions of the Linux kernel with user-space tooling, known as ‘distros’. They will often have a particular focus, such as for desktop or workstation use, enterprise server use, or deciding between cutting edge tooling and features or stability. The Red Hat family of distros, including Red Hat Enterprise Linux (RHEL) and derivaties of the now discontinued CentOs, including CentOs Stream, Rocky and Alma Linux focus on long-term stability and server applications. They are commonly used as a basis for HPC systems for these reasons. Fedora is from the same family, although targets more bleeding-edge tooling and has wider use in desktop application. Debian is another well known distro, with a community rather than enterprise focus. It also has a focus on long-term stability and is most used in server applications. A commerically-backed derivative, Ubuntu, is a highly popular distro with particular adoption in the desktop area.
Introduction#
Working with the shell#
The ‘shell’, ‘terminal’ or ‘console’ is a text-based user interface (TUI), as opposed to a graphical user interface (GUI) which many users will be more accustomed to. In the latter, the mouse plays an important role - along with interactive visual elements. The shell on the other hand focuses on text-based inputs and outputs. Text commands are input to trigger some process or action and text is generated and displayed as feedback.
The shell plays a fundamental role when working on Linux systems, and although GUI tools are prominent on Mac is also just as powerful on that system. The shell is provided by a ‘terminal emulator’ application, which a default one available on all systems. Within the terminal emulator a shell program enables the actual processing of commands and running of scripts, with the Bourne-Again SHell (Bash) being popular on Linux and the Z Shell (ZSh) being default on Mac.
Within the shell, some useful early commands are related to navigation, where you can do:
pwd # print path of current (working) directory
ls # list contents of current directory
la -alh # list contents of current directory, include hidden files (a), permissions (l) and human readably formatting (h)
cd my_path # change directory to my_path
cd .. # move 'up' one directory
Working with processes#
A typical activity when working with the shell is working with processes, or launching and inspecting running applciations.
The top
utility is available on most platforms and will show a list of running processes including their process identifier (PID), launch command and resource use. It will also show the overall system resource use. The htop
command gives a more user-friendly and detailed view, including the process hierarchy and detailed of spawned threads. It may need installation via the system package manager first however as it is often not installed by default.
The process status ps
command is available on all systems and with its flags is useful for producing more focused output than top
which is designed more for display. Some useful ps
commands are:
ps # show processes in the current shell
pa a # show processes for all users
ps -U my_user # show processes for my_user
ps -x # show all processes owned by the current user
The ps
command is often combined with a pipe and search via grep
to get info on a certain process or group of processes. For example to find processes related to Safari
we can do:
ps aux | grep Safari
If a process with PID my_pid
needs to be terminated it can be sent a SIGTERM
signal with:
kill my_pid
Other signals such as SIGKILL
can also be sent, in this case with the shortcut:
kill -9 my_pid