Operating Systems / Chapter 1: The Shell / The Shell

Logicwalk Operating System

In the Computer Architecture course, we represented the computer as a table. The table cells described the various parts of the computer's current state, such as the Program Counter and the values of the memory cells. The state helps us understand what is happening. Each time the computer takes a step, one or more table cell values change, like a series of photographs.

We could continue to use this model to study operating systems. After all, an operating system is a set of computer instructions like any other computer program. The problem is that the OS is a very large, complex program, with millions of instructions using millions of memory cells. It is very difficult to understand what the instructions are doing and which memory cells are being used for what purpose. Thus, we will use a more concise and descriptive representation of the a computer running an operating system.

We will still describe the operating system's state as a collection of its attributes. But rather than tracking instructions and memory cells, we will track parameters, or attributes. We will give attributes names so we can easily tell what they are for.

For example, the hostname identifies a computer in a network. There are also attributes that indicate whether someone has pressed a key on the keyboard or a new message was received from another computer. We will store these attributes in a map and study how they change as the computer is running.

Here is an example of the LWOS map:

  • hostname: "computer_1"
  • status: "idle"
  • interrupts:
    • keyboard: false
  • pressed_key: ""
  • shell:
    • user_input: ""
    • buffer: "> "
  • display_io
    • data: "> "
    • signal: false

According to this map, the hostname of the computer is "computer_1." The computer's status is "idle," which means that LWOS is not currently executing any commands. There is 1 interrupt called "keyboard," which contains a boolean value (currently false). The "shell" attribute contains information about the shell. the "user_input" is where the pressed keys are stored. The "buffer" is the text that will be displayed on the screen (initially the prompt "> ").

There is also the "display_io" sub-map. This map is shared between the OS and the display. LWOS uses this map to communicate with the display.

For convenience, to refer to child attributes, we will use the right arrow (->) notation. For example, the "buffer" attribute of the "shell" attribute is shell -> buffer.

Now suppose that the user presses a key on the keyboard. The keyboard sets interrupts -> keyboard to true. This is very similar to the behavior we saw in the Computer I/O course.

For example, after a user presses the "c" key, here is the new map:

  • hostname: "computer_1"
  • status: "idle"
  • interrupts
    • keyboard: true
  • pressed_key: "c"
  • shell
    • user_input: ""
    • buffer: "> "
  • display_io
    • data: "",
    • signal: false

The changes to the map are highlighted. The keyboard interrupts the computer by setting the value of interrupts -> keyboard to true. The pressed key, "c," is stored in the "pressed_key" attribute. Next, let's see what LWOS does when it is interrupted by the keyboard.

Previous Lesson Next Lesson

Comments

Please log in to add comments