No.10 How a computer works

The Mechanism of a Computer

A washing machine washes clothes using a motor, and a rice cooker heats up rice using a heater.  How does a computer work?

(Download PPT)


Template for “Spec of PC” (DOC | PDF)

Exercise 10-1(☆)
  1. When buying a beverage from a vending machine, what is the input, what kind of process is being executed and what is the output?
  2. In Exercise07-5, what is the input, process and output.
Exercise 10-2(☆☆☆)
  1. On Exercise 09-5, where are ex09-5.html and ex09-5.js stored ? Primary or secondary storage?
  2. When the “pocket” button is clicked, another “Inside the pocket, there’s two cookie” shows up. In which memory is this message saved on?
  3. When the page is reloaded, the screen returns to a single “Inside the pocket, there’s one cookie”. What happened to the data in the primary and secondary memories?
Exercise 10-3(☆)
  1. Start up the Activity Monitor(Applications→Utilities).
  2. The usage of the CPU is displayed under the “CPU” tab.  Open any application and see what happens.
  3. Check the disk activity monitor.  Open any application and see what happens.

With Windows8, the CPU usage can be displayed with the Task Manager

Operating System

The Operating System(OS) is software to manage the computer.  The basic functions of an operating system are:

Process Management
Manages the start-up, execution, termination of software.
Device Driver
The device driver manages parts of input and output to simplify the application.
File System
The unit “file” and “directory” is used to manage data easily on secondary memory.
Security
Manages accessing authorization of data and hardware.
User Interface
A computer is operated by GUI and CUI.

Commonly used operating systems are:

PC
Windows, MacOS, Linux(Ubuntu, etc)
Smart Phone
iOS, Android (Linux is used for kernel)
Server
Windows Server, Unix(Solaris, etc), Linux(RedHat, etc), Mainframe(z/OS, etc)

Process Management

The state of an application being executed is called a “process”.  The operating system manages processes, and terminates programs accordingly.

Exercise 10-4(☆☆)
  1. Start up the activity monitor and check what processes are in motion.
  2. Click “%CPU”, and line the processes in order of CPU usage.
  3. Operate the browser and editor and see if the order changes.
  4. Terminate a process by clicking on the apple mark.
  5. A warning should come up.  Explain what this means from the point of view of primary and secondary memory.

Processes can be terminated on Windows8 with the task manager.

File System

We studied about file systems in Lesson 3, and the main points are:

  • Contents of secondary storages are managed by directories (folders) and files.
  • Two files with the same name can be made if their directories are different.  To distinguish files of the same name, we need to use path names (absolute or relative).
Exercise 10-5(☆☆)
  1. Create ex10-5.txt inside the directory “fundamentals of information technology” we made (or any other directory you like), and write something in it.
  2. Confirm the absolute path of ex10-5.txt via editor.
    • With Atom, click the file name on the bottom left
    • With Emacs, the command M-x pwd will show the directory.
  3. Copy ex10-5.txt (drag with holding the option key) to the desktop.
  4. Open the file and compare the absolute path from before.
  5. Write a different text from the original file and save it.
  6. Did the content of the original file change?
  7. Make an alias of ex10-5.txt(option key + command key + drag, or right click the file and select “Make Alias”)
  8. Open the alias and change the content.
  9. Did the content of the original file change?
  10. Delete the original file.
  11. What happens when the alias is opened by the editor?
  • Copy will create a different file with the same content.  Files with the same name will be treated as a different file as long as they exist in different directories.
  • Alias adds a different name for the same file.  Even if the file name is different, it is still the same file.

In some cases, you don’t want other users to be able read and write your data. In that case, you change the file permissions.

(PPT版ダウンロード)

Normally, users work on their own directory and set the accessing authorization so that other users can’t overwrite any files.  However, a file can be shared to the public by changing the permission.  Let’s use the shared region and practice.

Exercise 10-6(☆☆☆☆)
  1. Create ex10-6.txt write something in and save the file.
  2. Select “Move to…” from from Finder and display the content of /pub/sfc/ipl/info1-free.  This is a shared region where anyone can make files.
  3. Move ex10-6.txt to /pub/sfc/ipl/info1-free.
  4. If the file with the same name has already been made by someone else, the file cannot be moved(because you don’t have the authorization to overwrite files.)  Change the file name and try moving the file.
  5. Ask the file name of your neighbor’s, and try opening the file with a editor.  What happens when you change the content and save the file?
  6. Right-click the file and select “Get Info”
  7. On the buttom of the info window, there is “Sharing and Permission” section.  “Everyone” is the column of authorization for other users.  What is it set to?
  8. Ask your neighbor to change the authorization of “Everyone” to read/write, and see if you can edit the file now.

Reviewing if statements and Loops

We studied if statements and loops before.  Now, let’s try combining the two.

There is a game called Fizz Buzz.  We count up from the number 1, and when the number is divisible by 3 we say “Fizz”, “Buzz” when the number is divisible by 5 and “Fizz Buzz” when the number is divisible by both 3 and 5.  Try doing this with your computer.

Exercise 10-7(☆☆☆)
  1. Edit Exercise 09-6 and display numbers from 1 to 30 in order (use a loop).
  2. How should we draw the flowchart (the diagram below) of the program? What goes into the condition and the process part?
  3. First, be able to display “Fizz” when the number is divisible by 3.  Where should we place the conditional branch(in the flowchart)?
  4. Make an if statement of the flowchart you drew.  The condition “divisible by 3” is written in a program as “when the remainder of a number divided by 3 is 0”.  The operant of a remainder is “%”.  When we want to find out the remainder of a variable named “count” when divided by 3, we write count % 3.
  5. Display “Fizz Buzz” when the number is divisible by 3 and 5.
  6. Display “Buzz” when the number is divisible by only 5.
Exercise 10-8(☆☆☆☆☆)

Display numbers from 1 to 99, and add “Ooops!” after numbers in case:

  • The number is divisible by 3.
  • The number contains 3 either on the one’s or ten’s place (such as 13 and 38).

If possible, use only one “if” statement. (Make a condition with logical operators)

Points to Check
  • What 5 functions are there in a computer.
  • How can we measure the performance of a CPU?
  • What is the difference of a primary and secondary memory?
  • What is a process?
  • Why is the access authorization set?