Abstract
This is the second edition of this book, written by Bryant O’Hallaron. This is a book be commented: a very heavy book, but as valuable as golden. This book shows how a program is running on system in quite detail. By reading it, you’ll know how your program is working and running. I’m reading the kindle version.
Content
1.1 Information Is Bits + Context
All information in a system - including disk files, programs stored in memory, user data stored in memory, and data transferred across a network - is represented as a bunch of bits. The only thing that distinguishes different data objects is the context in which we view them. For example, in different contexts, the same sequence of bytes might represent an integer, floating-point number, character string, or machine instruction.
Everyone is saying all things in computer is 0 and 1. No matter they really know computer or not. But what’s it really mean and how 0 and 1 could do so much?
This says all data are just a bunch of bits(0/1). Those bits keep the real content of information. But in order to interpret those content, you must also have context. Context is like metadata that let you know to read and understand those bits.
Files such as hello.c that consist exclusively of ASCII characters are known as text files. All other files are known as binary files.
This says text files are actually bits that could be interpreted by ASCII, which means if you remember the character table, you can even read those bits yourself. Others must be interpreted by corresonding application, so we can only see they’re binary. Since they’re more commong encoding rules know, like UTF-XXX, and even GKXXX for Chinese. I would say all data could be interpreted by those common encoding rules are text, so the file could be called text file.
1.4 Processors and Memory
Buses are typically designed to transfer fixed-sized chunks of bytes known as words.
word are important for system because of IO buess transfer data in size of chunks of words.
Logically, memory is organized as a linear array of bytes, each with its own unique address(array index) starting at zero.
As mentioned before, all information are stream of bits. we’ll need other context to interpret it, the same types could be interpreted as interger, float or even instruction.
At any point in time, the PC points at (contains the address of) some machine-language instruction in main memory. From the time that power is applied to the system, until the time that the power is applied to the system, until the time that the power is shut off, a processor repeatedly executes the instruction pointed at by the program counter and updates the program counter to point to the next instruction. In this model, instructions execute in strict sequence, and executing a single instruction involves performing a series of steps. The processor reads the instruction from memory pointed at by the program counter(PC), interprets the bits in the instruction, performs some simple operation dictated by the instruction, and then updates the PC to point to the next instruction, which may or may not be contiguous in memory to the instruction that was just executed.
These statements really show how PC is executing instructions, which could be the your coding program.
1.7 The Operating System Manages the Hardware
The program appears to have exclusive use of both the processors, main memory, and I/O devices.
Process is a very important abstraction for a running program. Within it, you don’t have to worry about other running program would affect yours. Every program would only care the process itself and assume the PC would only run the one process. Operating system would apply processes to manage different/multiple running program.
The operating system keeps track of all the state information that the process needs in order to run. This state, which is known as the context, includes information such as the current values of the PC, the register file, and the contents of main memory. At any point in time, a uniprocessor system can only execute the code for a single process.
The operating system manage multiple processes by switching running processes smartly. each time it switches, it need to save/load the context for current/next process. That’s how a single processor could run multiple processes. Those work are done by kernal code of operating system.
Threads are an increasingly important programming model because of the requirement for concurrency in network servers, because it is easier to share data between multiple threads than between multiple processes, and because threads are typically more efficient than processes.
Thread is different than process, as it enable take use of multiple processors while at the same time, memory could be sharing easily.
The heap expands and contracts dynamically at run time as a result of calls to C standard library routines such as malloc and free. In particular, each time we call a function, the stack grows. Each time we call a function, the stack grows. Each time we call a function, the stack grows. Each time we return from a function, it constracts.
Heap and stack both expand and contract dynamically.
A file is a sequence of bytes, nothing more and nothing less.
file is a just bytes in the process point of view.
Questions
History
- 2023-01-22: draft this post and record #1.1
- 2023-01-23: #1.4 how binary is executed in PC
- 2023-01-28: #1.8 operating system manage hardware by processes