Operating Systems and Using Linux Review Operating System

  • Slides: 41
Download presentation
Operating Systems and Using Linux • • • Review Operating System. Linux Overview. Frequently

Operating Systems and Using Linux • • • Review Operating System. Linux Overview. Frequently Used Linux Commands. Definition of an Algorithm Examples. CMSC 104, Section 301, Fall 2002 1 Lecture 04, 9/11/02

Review Operating System • A computer program. • Performs many operations, such as: •

Review Operating System • A computer program. • Performs many operations, such as: • Allows you to communicate with the computer (tell it what to do). • Controls access (login) to the computer. • Keeps track of all processes currently running. • At this point, your main concern is how to communicate with the computer using the OS. CMSC 104, Section 301, Fall 2002 2 Lecture 04, 9/11/02

Connecting to UMBC Linux Servers • See http: //www. umbc. edu/oit/pc_ppp/index. html for dtails.

Connecting to UMBC Linux Servers • See http: //www. umbc. edu/oit/pc_ppp/index. html for dtails. • Setup your PC for dial-up connections. • Dial 410 -719 -1094 or 301 -322 -6199 with your my. UMBC or gl account. (Helpdesk: 410 -455 -3838 or ECS 020). • Telnet to one of the following linux servers: • telnet linux 1. gl. umbc. edu • telnet linux 2. gl. umbc. edu • telnet linux 3. gl. umbc. edu CMSC 104, Section 301, Fall 2002 3 Lecture 04, 9/11/02

Connecting to UMBC Linux Servers CMSC 104, Section 301, Fall 2002 4 Lecture 04,

Connecting to UMBC Linux Servers CMSC 104, Section 301, Fall 2002 4 Lecture 04, 9/11/02

Connecting to UMBC Linux Servers CMSC 104, Section 301, Fall 2002 5 Lecture 04,

Connecting to UMBC Linux Servers CMSC 104, Section 301, Fall 2002 5 Lecture 04, 9/11/02

Connecting to UMBC Linux Servers CMSC 104, Section 301, Fall 2002 6 Lecture 04,

Connecting to UMBC Linux Servers CMSC 104, Section 301, Fall 2002 6 Lecture 04, 9/11/02

How Do I Communicate With the Computer Using the OS? (con’t) • When you

How Do I Communicate With the Computer Using the OS? (con’t) • When you log in to the Linux system here, a user prompt will be displayed: linux#[1]% _ where # is the number of the Linux server that you have connected to. You may use any of the Linux servers. • The number in the brackets will change as you work. It is the “number” of the command that you are about to type. • If this prompt is not on the screen at any time, you are not communicating with the OS. CMSC 104, Section 301, Fall 2002 7 Lecture 04, 9/11/02

Linux Overview • Files and Filenames. • Directories and Subdirectories. • Frequently Used Commands.

Linux Overview • Files and Filenames. • Directories and Subdirectories. • Frequently Used Commands. CMSC 104, Section 301, Fall 2002 8 Lecture 04, 9/11/02

Files • A file is a sequence of bytes. • It can be created

Files • A file is a sequence of bytes. • It can be created by o o a text editor (xemacs or pico), a computer program (such as a C program). • It may contain a program, data, a document, or other information. • Files that contain other files are called directories (sometimes called folders). CMSC 104, Section 301, Fall 2002 9 Lecture 04, 9/11/02

Linux Filenames • Restrictions o o o May not contain blanks or other reserved

Linux Filenames • Restrictions o o o May not contain blanks or other reserved characters. Have a maximum length. Are case sensitive. • It is best to stick with filenames that contain letters (uppercase or lowercase), numbers, and the underscore ( _ ) for now. CMSC 104, Section 301, Fall 2002 10 Lecture 04, 9/11/02

Directories • Directories contain files or other directories called subdirectories. They may also be

Directories • Directories contain files or other directories called subdirectories. They may also be empty. • Directories are organized in a hierarchical fashion. • They help us to keep our files organized. CMSC 104, Section 301, Fall 2002 11 Lecture 04, 9/11/02

Directories (con’t) /afs/umbc. edu/users/j/d/jdoe 28 junk recipes pies apple peach CMSC 104, Section 301,

Directories (con’t) /afs/umbc. edu/users/j/d/jdoe 28 junk recipes pies apple peach CMSC 104, Section 301, Fall 2002 cmsc 104 cookies projects lectures choc_chip 12 Lecture 04, 9/11/02

Directories (con’t) • Your home directory is where you are located when you log

Directories (con’t) • Your home directory is where you are located when you log in (e. g. , /afs/umbc. edu/users/j/d/jdoe 28). • The current directory is where you are located at any time while you are using the system. • Files within the same directory must be given unique names. • Paths allow us to give the same name to different files located in different directories. • Each running program has a current directory and all filenames are implicitly assumed to start with the name of that directory unless they begin with a slash. CMSC 104, Section 301, Fall 2002 13 Lecture 04, 9/11/02

Moving in the Directory Tree • . (dot) is the current directory. • .

Moving in the Directory Tree • . (dot) is the current directory. • . . (dot-dot) is the parent directory. • Use the Linux command cd to change directories. o o o Use dot-dot to move up the tree, e. g. , cd. . Use the directory name to move down, e. g. , cd cmsc 104. Use the complete directory name (path name) to move anywhere, e. g. , cd cmsc 104/proj 1. CMSC 104, Section 301, Fall 2002 14 Lecture 04, 9/11/02

Wildcard Characters • You will find wildcard characters useful when manipulating files (e. g.

Wildcard Characters • You will find wildcard characters useful when manipulating files (e. g. , listing or moving them). • The wildcard characters are * and ? . • ? is used to represent any single character. • * is used to represent 0 or more characters. CMSC 104, Section 301, Fall 2002 15 Lecture 04, 9/11/02

Frequently Used Linux Commands • pwd – present working directory to check where you

Frequently Used Linux Commands • pwd – present working directory to check where you are in the directory tree. • ls – list of files or subdirectories, e. g. , ls proj* or ls –l. • cd – change directory to pathname, cd pathname. • cp – copy files from file 1 to file 1 b, e. g. , cp file 1 b. • mv – rename file from file 1 to file 2, e. g. , mv file 1 file 2. • rm – remove (delete) files, e. g. , file 1 file 2 … • mkdir – make directory dir-name, e. g. mkdir dir-name. • rmdir – remove (delete) directory, e. g. rmdir dir-name. • man – look up how to use the command, man cp. • passwd – to change password. • ctl-c – to terminate command, process, … • Other commands: cat, more. CMSC 104, Section 301, Fall 2002 16 Lecture 04, 9/11/02

Frequently Used Linux Commands References: • Linux man page. • Links from the cmsc

Frequently Used Linux Commands References: • Linux man page. • Links from the cmsc 104 homepage. http: //www. cs. umbc. edu/courses/undergraduate/104/fall 02/chen/ • Books and the Internet. CMSC 104, Section 301, Fall 2002 17 Lecture 04, 9/11/02

Examples • For example, o make a subdirectory for cmsc 104, e. g. ,

Examples • For example, o make a subdirectory for cmsc 104, e. g. , – mkdir cmsc 104, cd cmsc 104, and – make subdirectories for projects, lectures, homeworks, exams, e. g. , mkdir projects homeworks exams lectures. o Directory tree: cmsc 104 exams homeworks ex 1 ex 2 final hw 1 … hwn CMSC 104, Section 301, Fall 2002 18 lectures L 1 … Ln projects proj 1 … projn Lecture 04, 9/11/02

CMSC 104, Section 301, Fall 2002 19 Lecture 04, 9/11/02

CMSC 104, Section 301, Fall 2002 19 Lecture 04, 9/11/02

CMSC 104, Section 301, Fall 2002 20 Lecture 04, 9/11/02

CMSC 104, Section 301, Fall 2002 20 Lecture 04, 9/11/02

CMSC 104, Section 301, Fall 2002 21 Lecture 04, 9/11/02

CMSC 104, Section 301, Fall 2002 21 Lecture 04, 9/11/02

 • • • linux 1[3]% ls -l drwxr-xr-x 2 lichen lrwxr-xr-x 1 lichen

• • • linux 1[3]% ls -l drwxr-xr-x 2 lichen lrwxr-xr-x 1 lichen drwxr-xr-x 2 lichen drwx------ 3 lichen lrwxr-xr-x 1 lichen 32 32 32 2048 7 2048 10 access # links owner group r: read w: write x: execute l: link d: directory CMSC 104, Section 301, Fall 2002 Sep 9 15: 49 Desktop Sep 2 00: 38 Mail ->. . /Mail Aug 13 1998 bin Sep 10 15: 25 li Sep 2 00: 38 www ->. . /pub/www file size last modified date filename 22 Lecture 04, 9/11/02

Algorithms, Part 1 of 3 Topics • Definition of an Algorithm. • Algorithm Examples.

Algorithms, Part 1 of 3 Topics • Definition of an Algorithm. • Algorithm Examples. • Syntax versus Semantics. Reading • Sections 3. 1 - 3. 3 CMSC 104, Section 301, Fall 2002 23 Lecture 04, 9/11/02

Problem Solving • Problem solving is the process of transforming the description of a

Problem Solving • Problem solving is the process of transforming the description of a problem into the solution of that problem. • We use our knowledge of the problem domain. • We rely on our ability to select and use appropriate problem-solving strategies, techniques, and tools. CMSC 104, Section 301, Fall 2002 24 Lecture 04, 9/11/02

Algorithms • An algorithm is a step by step solution to a problem. •

Algorithms • An algorithm is a step by step solution to a problem. • Why bother writing an algorithm? o o For your own use in the future. You won’t have to rethink the problem. So others can use it, even if they know very little about the principles behind how the solution was derived. CMSC 104, Section 301, Fall 2002 25 Lecture 04, 9/11/02

Examples of Algorithms • Washing machine instructions. • Washing hair instructions (ambiguous algorithm). •

Examples of Algorithms • Washing machine instructions. • Washing hair instructions (ambiguous algorithm). • A classic: finding the greatest common divisor (GCD) using Euclid’s Algorithm. CMSC 104, Section 301, Fall 2002 26 Lecture 04, 9/11/02

Washing Machine Instructions • Separate clothes into white clothes and colored clothes. • If

Washing Machine Instructions • Separate clothes into white clothes and colored clothes. • If white clothes: o Set water temperature knob to HOT. o Place white laundry in tub. • If colored clothes: o Set water temperature knob to COLD. o Place colored laundry in tub. • Add 1 cup of laundry detergent to tub. • Close lid and press the start button. CMSC 104, Section 301, Fall 2002 27 Lecture 04, 9/11/02

Washing Machine Instructions (con’t) Observe that • There a finite number of steps. •

Washing Machine Instructions (con’t) Observe that • There a finite number of steps. • We are capable of doing each of the instructions. • When we have followed all of the steps, the washing machine will wash the clothes and then will stop. CMSC 104, Section 301, Fall 2002 28 Lecture 04, 9/11/02

Refinement of Algorithm Definition • Our old definition: o An algorithm is a step

Refinement of Algorithm Definition • Our old definition: o An algorithm is a step by step solution to a problem. • Adding our observations: o An algorithm is a finite set of executable instructions that directs a terminating activity. CMSC 104, Section 301, Fall 2002 29 Lecture 04, 9/11/02

Ambiguous Algorithms Washing Hair Instructions: 1. Lather. 2. Rinse. 3. Repeat. How could these

Ambiguous Algorithms Washing Hair Instructions: 1. Lather. 2. Rinse. 3. Repeat. How could these instructions be hard to follow? CMSC 104, Section 301, Fall 2002 30 Lecture 04, 9/11/02

Final Version of the Algorithm Definition • Our old definition: o An algorithm is

Final Version of the Algorithm Definition • Our old definition: o An algorithm is a finite set of executable instructions that directs a terminating activity. • Final version: o An algorithm is a finite set of unambiguous, executable instructions that directs a terminating activity. CMSC 104, Section 301, Fall 2002 31 Lecture 04, 9/11/02

History of Algorithms • The study of algorithms began as a subject in mathematics.

History of Algorithms • The study of algorithms began as a subject in mathematics. • The search for algorithms was a significant activity of early mathematicians. • Goal: To find a single set of instructions that can be used to solve any problem of a particular type (a general solution). CMSC 104, Section 301, Fall 2002 32 Lecture 04, 9/11/02

Euclid’s Algorithm Problem: Find the largest positive integer that divides evenly into two given

Euclid’s Algorithm Problem: Find the largest positive integer that divides evenly into two given positive integers, i. e. , the Greatest Common Divisor (GCD). Algorithm: 1. Let M, N be two positive integers, where M > N. 2. Divide M by N and call the remainder R. 3. If R is not 0, then Let M = N, N=R. Go to step 2. 4. Else (R = 0) GCD = N. CMSC 104, Section 301, Fall 2002 33 Lecture 04, 9/11/02

Finding the GCD of 24 and 9 M 24 9 6 N 9 6

Finding the GCD of 24 and 9 M 24 9 6 N 9 6 3 R 6 3 0 Done. So, 3 is the GCD of 24 and 9. CMSC 104, Section 301, Fall 2002 34 Lecture 04, 9/11/02

Euclid’s Algorithm (con’t) • Do we need to know theory that Euclid used to

Euclid’s Algorithm (con’t) • Do we need to know theory that Euclid used to come up with this algorithm in order to use it? • What intelligence is required to find the GCD using this algorithm? CMSC 104, Section 301, Fall 2002 35 Lecture 04, 9/11/02

The Idea Behind Algorithms • Once an algorithm behind a task has been discovered.

The Idea Behind Algorithms • Once an algorithm behind a task has been discovered. o We don't need to understand the principles. o The intelligence is "encoded into the algorithm. “ o The task is reduced to following the instructions. CMSC 104, Section 301, Fall 2002 36 Lecture 04, 9/11/02

Algorithm Representation • Syntax and Semantics o Syntax refers to the representation itself. o

Algorithm Representation • Syntax and Semantics o Syntax refers to the representation itself. o Semantics refers to the concept represented (i. e. , the logic). CMSC 104, Section 301, Fall 2002 37 Lecture 04, 9/11/02

Contrasting Syntax and Semantics • In the English language, we have both syntax and

Contrasting Syntax and Semantics • In the English language, we have both syntax and semantics. • Syntax is the grammar of the language. • Semantics is the meaning. • Given the following sentence, I walked to the corner grocery store. o o Is this sentence syntactically correct? Is it semantically correct? CMSC 104, Section 301, Fall 2002 38 Lecture 04, 9/11/02

Contrasting Syntax and Semantics (con’t) • Given the following sentence, I talked to the

Contrasting Syntax and Semantics (con’t) • Given the following sentence, I talked to the funny grocery store. o o Is this sentence syntactically correct? Is it semantically correct? • How about I grocery store walked corner the to. CMSC 104, Section 301, Fall 2002 39 Lecture 04, 9/11/02

Contrasting Syntax and Semantics (con’t) • Conclusion: An English sentence may be syntactically correct,

Contrasting Syntax and Semantics (con’t) • Conclusion: An English sentence may be syntactically correct, yet semantically incorrect. • This is also true of algorithms. • And it is also true of computer code. • Note that it only makes sense to consider semantic if syntax is correct. CMSC 104, Section 301, Fall 2002 40 Lecture 04, 9/11/02

Next • More problem solving and algorithms. • Pseudocode. • Assignment: o o Read

Next • More problem solving and algorithms. • Pseudocode. • Assignment: o o Read 3. 1 – 3. 10 (skip the C code, just the pseudocode. ) Login to one of the linux servers, perform some of the unix commands from home or school. – linux 1. gl. umbc. edu – linux 2. gl. umbc. edu – linux 3. gl. umbc. edu CMSC 104, Section 301, Fall 2002 41 Lecture 04, 9/11/02