-
Notifications
You must be signed in to change notification settings - Fork 1
Linux Architecture
Operating systems are a core part of software. They act as an intermediary layer between hardware and applications ensuring portability across different hardware components and system integrity.
In this chapter we discuss the common software stack of modern computing systems, focusing on Linux and the interfaces provided to the user and the developer.
After this chapter you will get a better understanding of the need and the roles of operating systems. Focus is on the user/developer interface with the aim of become a more proficient user of the CLI shell. You will understand the roles of layers in the software stack and become familiar with the use cases for each programming interface (i.e. API). Furthermore you will gain system investigation skills such as hardware inspection, process investigation and resource consumption; these are important in diagnosing problems and identifying bottlenecks.
computing systems, operating systems CPU, memory, I/O portability, security, interfacing overhead user, shell, interface CLI, terminals, shell features (completion, history), terminal multiplexers system call interface, library interface API and ABI ANSI C API, POSIX API, Windows API (Win32, Win64) system call tracing kernel configuration: command line, sysctl, virtual filesystems
The SHELL environment variable points to the current shell. The process ID is $$. The current terminal is shown by the tty command. Opening a new shell tab creates a new terminal and a new shell running in that.
Tab is used for command completion. Tab-Tab is used for multiple options.
We use reverse search to look for previous commands: press Ctrl-r then insert text part of a previous command.
Use Alt+. for the last argument of the last command.
Readline is a library for command line editing and moving in the command: TODO link
Terminal multiplexers are used to easily create multiple shell sessions, sharing screens and for keep alive remote shell sessions. tmux, screen and byobo are primary examples. We show use of terminal multiplexers for local sessions and remote sessions. tmux is configured in ~/.tmux.conf.
ANSI C is standard portable API. It has the advantage of portability but doesn't provide all features (i.e. threads, IPC, asynchronous I/O). POSIX API is an API for POSIX-compliant (actually close to POSIX-compliant) systems. The OS provides a system API (system call interface). In Linux, the system API is closely connected to the POSIX API. POSIX and ANSI C are implemented in the standard C library.
We show multiple fopen() calls and what system calls they make by tracing them using strace and ltrace: 01-linux-architecture/fopen-perm/.
We show the correspondence between POSIX API and system API and cases where they don't match: creating a process and a thread: 01-linux-architecture/posix-vs-syscall.
We trace a running shell and see what happens when it runs a command.
Tracing is used for inspection and for debugging: what happens when a process crashes or blocks.
The core of the operating system is the kernel. The Linux kernel exposes a configuration and inspection interface in the procfs filesystem in Linux, used by process, I/O and memory inspection commands: ps, free, top, lsof. The kernel is configured in /proc/sys or by using the sysctl command.
There are commands for inspecting the operating system: uname, cat /etc/issue, lsb_release -a, getconf -a.
Commands for inspecting hardware and hardware use: lshw, lscpu, lspci, lsusb, lsblk, free, uptime, inxi.
- connect to remote Docker instance and use tmux, name session, share session, use read-only:
ssh -l training 141.85.224.70 -p 2222 - convert a program from using ANSI calls to using POSIX API:
01-linux-architecture/ansi-to-posix. - convert a program from using POSIX API to directly use system calls (
syscall()):01-linux-architecture/posix-to-syscall - what does the
system()invoke? what does thesleep()call invoke?:01-linux-architecture/syscall-trace - what library call does
printf()make? (puts()):01-linux-architecture/printf-puts - tracing a dynamic and static executable with
straceandltrace: use01-linux-architecture/ansi-to-posix:gcc -static -o ansi-to-posix-static ansi-to-posix.c -I../../util - find out page size by using the
getconfcommand, thegetconf()call and thegetpagesize()calls. What library/system calls are they making?01-linux-architecture/page-size