Operating Systems / Chapter 4: Programs / Python

Print

The print function asks LWOS to print some text to the shell. The function definition is:

def print(text)

    text should be printed in the shell (type string)

    this function does not return anything

For example, suppose we called

print("Hello World!")

As with all function calls, the argument will be evaluated first and added to the top of the Values Stack. Next, python is going to update the python map to:

  • python
    • state: "blocked",
    • io
      • type: "shell",
      • data: "101 Park Street, Seattle"

python -> state is now "blocked." After each python step, LWOS checks python -> state. If it is "blocked," LWOS pause the python program and inspect python -> io. When python -> io -> type is "shell," LWOS will update status to "waiting_on_display" and ask the display to print the text by:

  • Appending "101 Park Street, Seattle" to shell -> buffer.
  • Copying shell -> buffer to display_io -> data.
  • Setting display_io -> signal to true.

Here is an example LWOS map:

  • hostname: "computer_1"
  • command: "python"
  • status: "waiting_on_display"
  • shell
    • buffer: "> python serve_books.py
      101 Park Street, Seattle
  • display_io
    • data: "> python serve_books.p
      101 Park Street, Seattle
    • signal: false

LWOS then waits for the shell to print the text.

After the shell has completed printing, it interrupts LWOS. When the command is "python" and status is "waiting_on_display," LWOS will resume python program execution.

At this point, python is still evaluating the "print" function call, and python -> state is still "blocked." Python will now pop the argument from the Values Stack and push None into the top of the Values Stack(nothing is returned). It also updates the state to "running" so that LWOS does not pause program execution again.

Quiz (1 point)

Please write python code that asks LWOS to print "It is a good day to code!" to the shell

Become a subscriber to save your progress, see the correct answer, and more!
Quiz (1 point)

Please fill in the blank.

When executing the "print" function, python updates the python map to:

  • python
    • state: "blocked",
    • io
      • type: "_________",
      • data: "It is a good day to code!"

Become a subscriber to save your progress, see the correct answer, and more!
Previous Lesson Next Lesson

Comments

Please log in to add comments