05 - Intro to LinuxOutlineGoalsInterfacesInternalsSource CodePortable Operating System Interface (POSIX)Standard Utility ProgramsStandard LibraryAnnouncementsReading: MOS 10.2, LDD 1GoalsEvolved from UNIX Goals (not predefined):Torvalds started with his MINIX-based kernel, letmany other devs work on it, and Linux evolved vianatural selection from user feedback.There are several levels of interfaces used tointeract and program in the Linux environment.POSIX is published by IEEE and the Open GroupPOSIX defines standard system calls, programminginterfaces (libraries), and shell programs (UI)In "core services", among other things:- Process creation and control- Signals- File system operations- Pipes- C library- I/O port interface and control- Process triggersAlso required:- Synchronization primitives- Threads (pthread)- Shell- etc.Linux ships with a set of core set of utilityprograms:- File system manipulation- Text filters- Editors and compilers- System administration- Etc.GNU C standard library provides functions from Clanguage definitionKernel provides C definitions for system callsSystem calls are special assemblyinstructions and need to be exposed to Clanguage at compile time.syscall() is defined in a header, butimplemented in assembly, symbol visible atlink-time.(e.g. printf, scanf, etc.) see(e.g. read, write, fork, etc.)libc provides wrapper functions for convenienceon particular architectures.POSIX requires C standard functions and UNIXsystem calls to be defined, but not necessarilydefined by kernel.The kernel is modular and generally organizedaccording to functionality.The textbook presents a simplified view:Realistically, there is a lot more going on.Compiled kernel lives in /boot/vmlinuz-X.Y.ZSource download:Official Documentation:We will install as a package:Directory is 1.5 GB code -> 20 GB compiledInteresting directories:Useful exploration tools:Bootlin (web-based code indexing tool)Cscope (TUI code indexer/browser)- Browse code of different Linux versions- Search for symbols/identifiers- Look up declarations and definitions- Install:- Index:- Start:- Exit:- Search: - C identifiers/symbols (e.g. start_kernel) - Function/variable definitions - Function calls - Strings- Usage: - `tab`: switch between menu and results - `arrows`: move between menu items - `space`: see more results - `enter`: search or select item (opens vi)- Check source tree version:- For a particular version:- bootloader will allow you to select one- see current version with `uname -a`kernel.org/pub/linux/kernel/vX.Y/linux-X.Y.Z.tar.{gz|xz}sudo apt install linux-sourcemake kernelversionExamples from MOS Figure 10-2:The current version isThese interfaces are mostly compliant with thePOSIX standard.- Multiuser, modular, monolithic kernel- Everything is a file- Free and Open Source Software (FOSS)But modern Linux does not adhere completely."UNIX Philosophy":- Douglas McIlroy (invented the UNIX pipe)- Make it easy to write, test, and run programs- Economy/Elegance due to size constraints- Constant maintenance & improvementWrite programs that do one thing and do it well.Write programs that work together.Write programs to handle text streams, because that is a universal interface.InterfacesInternalsPA 1 is due today. I hope you started.I will release PA2 instructions by tonight.1)2)3)UsersStandard Utility Programs(shell, editor, compilers, etc.)Standard Library(open, close, read, write, fork, etc.)Linux Kernel(proc management, mem management, file system, I/O, etc.)Hardware(CPU, memory, disks, terminals, etc.)UserInterfaceLibraryInterfaceSyscallInterfaceMOS Figure 10-1POSIX.1-2024catchmodcpcutgrepheadlsmakeodpasteprpsrmrmdirsorttailtrmkdirconcatenate files and print on the standard outputchange file mode bitscopy files and directoriesremove sections from each line of filesprint lines that match patternsoutput the first part of fileslist directory contentsGNU make utility to maintain groups of programsmake directoriesdump files in octal and other formatsmerge lines of filesconvert text files for printingreport a snapshot of the current processesremove files or directoriesremove empty directoriessort lines of text filesoutput the last part of filestranslate or delete characters; Use the 'read' syscall (number 0) from stdin (fd 0)mov rax, 0 ; syscall number for 'read'mov rdi, 0 ; file descriptor 0 (stdin)mov rsi, buffer ; address of buffer to store inputmov rdx, buffer_len; maximum number of bytes to readsyscall ; invoke kernelseeCygwin,WSL1C StandardMOS Figure 10-3Linux Kernel Mapinteractive diagraminteractive mapLinux Kernel Archivesdocs.kernel.orgarch/ISA-specific code (boot process, context switch, etc.)header fileskernel initialization code (not arch-specific)memory managementdevice driversinter-process communicationfile systemgeneric kernel corenetworkingblock memory deviceshelper/utility librariesconfig and compilation scriptsself-explanatoryfunction/mechanism examplesuser space programs/scripts for debugging, tracing, etc.include/init/mm/drivers/ipc/fs/kernel/net/block/lib/scripts/Documentation/samples/tools/sudo apt install cscopemake cscopecscopeCtrl-d