Linux – The big picture

Levels and Layers  of  Abstraction  in  a  Linux  System

  • Hardware:  Understanding Main Memory
    • This is where the running kernel and processes reside—they’re just big collections of bits.
  • The Kernel – One of the kernel’s tasks is to split memory into many subdivisions, and it must always maintain certain state information about those subdivisions. Each process gets its own share of memory, and the kernel must ensure that each process keeps to its share.
  • The kernel is in charge of managing tasks in four general system areas:
    • Processes. The kernel is responsible for determining which processes are allowed to use the CPU.
    • Memory. The kernel needs to keep track of all memory—what is currently allocated to a particular process, what might be shared between processes, and what is free.
    • Device drivers. The kernel acts as an interface between hardware (such as a disk) and processes. It’s usually the kernel’s job to operate the hardware.
    • System calls and support. Processes normally use system calls to communicate with the kernel.
  • Because it gives new readers context. What are you about? Why should they read your blog?
  • Because it will help you focus your own ideas about your blog and what you’d like to do with it.
  • Process Management

Process management describes the starting, pausing, resuming, and terminating of processes. The concepts behind starting and terminating processes are fairly straightforward, but describing how a process uses the CPU in its normal course of operation is a bit more complex.

Each piece of time—called a time slice—gives a process enough time for significant computation (and indeed, a process often finishes its current task during a single slice). However, because the slices are so small, humans can’t perceive them, and the system appears to be running multiple processes at the same time (a capability known as multitasking).

The kernel is responsible for context switching. To understand how this works, let’s think about a situation in which a process is running in user mode but its time slice is up. Here’s what happens:

  1. The CPU (the actual hardware) 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 and memory, which will be essential to resuming the process that was just interrupted.
  3. The kernel performs any tasks that might have come up during the preceding time slice (such as collecting data from input and output, or I/O, operations).
  4. The kernel is now ready to let another process run. The kernel analyzes the list of processes that are ready to run and chooses one.
  5. The kernel prepares the memory for this new process, and then prepares 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 and hands control of the CPU to the process.
  • Memory Management

Because the kernel must  manage  memory  during  a  context  switch,  it  has  a  complex  job  of  memory management. The kernel’s job is complicated because the following conditions must hold:

  1. The kernel must have its own private area in memory that user processes can’t access.
  2. Each user process needs its own section of memory.
  3. One user process may not access the private memory of another process.
  4. User processes can share memory.
  5. Some memory in user processes can be read-only.
  6. Modern  CPUs  include  a  memory  management  unit  (MMU)  that enables a memory access scheme called  virtual memory.
  7. Device Drivers and Management

A device is typically accessible only in kernel mode because improper  access  (such  as  a  user  process  asking  to  turn  off  the  power)  could  crash  the  machine.  Another problem is that different devices rarely have the same programming interface, even if the devices do the same thing, such as two different network cards. Therefore, device drivers have traditionally been part of the kernel, and they strive to present a uniform interface to user processes in order to simplify the software developer’s job.

  • System Calls and Support

Two system calls, fork() and exec(), are important to understanding how processes start up:

  1. fork() When a process calls fork(), the kernel creates a nearly identical copy of the process.
  2. exec() When a process calls exec(program), the kernel starts program, replacing the current process.

All user processes on a Linux system start as a result of fork(), and most of the time, you also run  exec()  to start a new program instead of running a copy of an existing process. Figure shows the flow of processes and system calls for starting a program like ls.

User  Space

the main  memory  that  the  kernel  allocates  for  user  processes  is  called  user  space

Users

A user  is an entity that can run processes and own files. A user is associated with a username. Users exist primarily to support permissions and boundaries. Every user-space process has a user owner, and processes are said to run  as  the owner. A user may terminate or modify the behavior of its own processes (within certain limits), but it cannot interfere with other users’ processes. In addition, users may own files and choose whether they share them with other users. The root user is an exception to the preceding rules because root may terminate and alter another user’s processes and read any file on the local system. For this reason, root is known as the superuser.

Reference: How Linux Works: What Every Superuser Should Know by Brian Ward


Discover more from Embedded for All

Subscribe to get the latest posts sent to your email.

Leave a comment

Discover more from Embedded for All

Subscribe now to keep reading and get access to the full archive.

Continue reading

Design a site like this with WordPress.com
Get started