Ch. 1: The Big Picture

지니🧸·2022년 7월 5일
0

운영체제

목록 보기
1/28
post-thumbnail

1.1 Levels and Layers of Abstraction in a Linux System

layer/level: classification of components according to where theh components sit b/w the user & the hardware
(ex) web browsers, games - top layer; memory in the computer hardware - bottom layer; operating system - layers in between

Linux system has 3 main levels

  • hardware: at the base
    includes: the memory, 1 or more central processing units (CPU) to perform computation and to read from and write to memory, disks, and network interfaces
  • kernel: sotware residing in memory that tells the CPU where to look for its next task
    the core of operating system
    acts as mediator --> manages hardware & is primary interface b/w hardware and any running program
    includes: system calls, process management, memory management, device drivers
  • (user) process: the running programs that the kernel manages
    collectively makes up the system's upper level, called user space
    includes: graphical user interface, servers, shell

How it runs: Kernel vs. User process

  • kernel runs in kernel mod; user process runs in user mode
  • kernel mode: unrestriced access to processor & main memory
    • powerful yet dangerous privilege: allows kernel to easily corrupt & crash system
    • kernel space: memory area that only the kernel can access
  • user mode: restricts access to subset of memory & safe CPU operations
    • user space: parts of main memory that user processes can access
    • mistakes in process has limited consequences & cleaned up by th kernel
      • some mistakes may be critical
  • Linux kernels can run kernel threads
    • look like processes but w/ access to kernel space

1.2 Hardware: Understanding Main Memory

main memory: a big storage area for 0s and 1s

  • through which all input & output from peripheral devices flow as bits
    bit: each slot for 0 or 1
  • running kernel & processes are big collections of bits
    CPU: operator on memory
  • reads instructions & data from the memory and writes data back out to the memory
    state: particular arrangement of bits
  • (ex) for 4 bits, 0110, 0001, and 1011 represent 3 different states
  • it's easier to use abstract terms with states b/c a signle process can consist of millions of bits
  • image: particular physical arrangement of bits

1.3 The Kernel

Kernel's task

  • split memory into many subdivisions
  • maintain certain state information about those subdivisions
  • ensure that each process keepts to its share of memory
  • manage tasks in 4 general system areas:
    • process: kernel determins which processes are allowed to use the CPU
    • memory: kernel keeps track of all memory: what is currently allocated to a particular process, what might be shared b/w process, what is free
    • device drivers: kernel acts as an interface b/w hardware (i.e. disk) & processes; kernel operates the hardware too
    • system calls and support: processes normally use system calls to communicate w/ the kernel

1.3.1 Process Management

Process Management: the starting, pausing, resuming, scheduling, and terminating of processes

  • on any modern os, processes seem to run simultaneously but they typically don't exactly do that
  • when system has one-core CPU, many processes are able to use the CPU, but only one process can actually use the CPU at any given time
  • context switch: act of one process giving up control of the CPU to another process
  • a time slice (or each piece of time) gives a process enough time for significant computation
  • multitasking: running multiple processes at the same time
    • the system appears to be multitasking b/c people can't notice the small slices

Context Switching (done by the kernel)
1. The CPU interrupts the current process based on an internal timer, switches into kernel mode, and hands control back to the kernel
2. The kernel records the current state of the CPU & memory (essential to resuming the process that was just interrupted)
3. The kernel performs any tasks that might have come up during the preceding time sluce (i.e. collecting data from input & output (I/O), operations)
4. The kernel is now ready to let another process run. It analyzes the list of processes ready to run & chooses one
5. The kernel prepares the memory for this new process and then compares the CPU
6. The kernel tells the CPU how long the time slice for the new process will last
7. The kernel switches the CPU into user mode & hands control of the CPU to the process

  • The context switch answers the question of when the kernel runs: b/w process time slices during a context switch
  • it's more complicated w/ multi-CPU systems b/c the kernel doesn't need to give up control of its current CPU to allow a process to run on a different CPU (multiple processes possible at a time), but kernel usually does the steps anyways to maximize the usage of all available CPUs

1.3.2 Memory Management

The kernel must manage memory during a context switch

  • kernel must have its own private area in memory that user processes can't access
  • each user process needs its own section of meemory
  • one user process may not access the private memory of another process
  • user processes can share memory
  • some memory in usre processes can be read-only
  • the system can use more memory than is physically present by using disk space as auxiliary

Modern CPUs include a memory management unit (MMU)

  • MMU: enables a memory access scheme called virtual memory
  • w/ virtual memory, a process does not directly access the memory by its physical location in hardware but the kernel sets up each process to act as if it had an entire machine to itself
    • when the process accesses some of its memory, the MMU intercepts the access & uses a memory address map to translate the memory location from the process POV into an actual physical location in the machine
    • the kernel must initialize & continuously maintain/alter this memory address map
      • page table: the implementation of a memory address map

1.3.3 Device Drivers and Management

A device is typically accessible only in kernel mode b/c improper access could crash the machine. A difficulty is that different devices rarely have the same programming interface despite performing the same task.
Thus, device drivers have traditionally been part of the kernel, trying to present a uniform interface to user processes & simplify the programmer's job

1.3.4 System Calls and Support

System Calls (syscalls): performs specific tasks (i.e. opening/reading/writing files) that a user process cannot do well or at all alone

  • fork() : when a process calls fork(), the kernel creates a nearly identical copy of the process
    • all new user processes on a Linux system, except init, starts as a result of fork()
  • exec() : when a process calls exec(program), the kernel loads.& starts program, replacing the current process
    • run exec() to start a new program instead of running a copy of an existing process
  • ls : the shell that's running inside the terminal window calls fork() to create a copy of the shell & the new copy of the shell calls exec(ls) to run ls
    The kernel also supports user processes w/ features other than traditional system calls
    Pseudodevices: looks like devices to user process but implemented purely in software
  • they don't need to be in the kernel but just there for practical reasons
  • technically a user process that accesses a pseudodevice must use a system acll to open the device so processes can't entirely avoid system calls

1.4 User Space

User space: the main memory that the kernel allocates for user processes

  • also refers to the memory for the entire collection of running processes
  • where most of the real action on a Linux system happens
    All processes are equal from the kernel's POV, but they perform different tasks for users. There exists a fundamental service level/layer structure to the kinds of system components that user processes represent.
  • basic services (network configuration, commmunication bus, diagnostic logging): at the bottom & closest to the kernel
    • consists of small components that perofrm single, uncomplicated tasks
  • utility services (name chacing server): in the middle
    • includes larger components (i.e., mail, print, and database services)
  • applications (user interface, web browser): at the top & closest to the user
    • includes complicated tasks that the user often controls directly
      Components may use other components. In that case, the used component is either at the same service level or below.
      Some components are difficult to categorize.

1.5 Users

The Linux kernel supports the traditional concept of a Unix user.
User: an entity that can run processes and own files

  • associated w/ a username
    • the kernel doesn't manage the usernames but identifies users by user IDs (numeric identifiers)
  • exist to support permissions & boundaries
    • every user-space process has a user owner & processes are said to run as th owner
    • a user may terminate/modify the behavior of its own processes but cannot interfere w/ other users' processes
    • users may own files & choose to share them w/ others
      A Linux system usually has a number of users on top of the ones that correspond to real human beings who use the system
      Root user: an exception to the preceding rules
  • root may terminate & alter another user's processes
  • access any file on the local system
  • also known as the superuser
  • one w/ root access is an administrator on a traditional Unix system
  • root access may be dangerous but it still runs in the OS's user mode (not kernel mode)
profile
우당탕탕

0개의 댓글