Download presentation
Presentation is loading. Please wait.
Published byChristina Snow Modified over 9 years ago
1
Lesson 1
2
PC vs. Multi-user System Personal Computer – each user gets his/her own processor (or multicore processor). Multi-user system – The processor, RAM, disk, and i/o devices are shared among several users. This can be accomplished through: multitasking timesharing
3
What is an Operating System? An OS is software (i.e. a computer program) that manages your computer. Its main jobs are: Manage software Enable interaction with a user Control peripherals (e.g. disk, printer)
4
What is UNIX? Unix is an operating system for multi-user systems. Developed originally at Bell Labs in 1969 by Thompson and Ritchie. It is an Open System (no single company owns it). It is portable – it can be installed on different types of machines.
5
Main components of UNIX OS: Kernel. Master control program of the computer. In charge of managing resources and multitasking. File System. Data is stored in files, which are organized in directories. Shell. Accepts user commands and passes them on to the Kernel. Utilities. These are the commands that UNIX understands.
6
Review: Jobs of an OS Manage software…. Kernel. Interact with User…. Shell (using utilities). Control peripherals…. all peripherals are part of the UNIX File System. In summary: You type a “utility” into the UNIX Shell, which gets passed to the Kernel for processing.
7
Your UNIX Account Since many users share one large disk, each user is given a “piece” of the disk, called an account. Each part of the disk has permissions associated with it. You will have permission to view only your own files. In order to work in your account, you will login with a username and password. (to be done before our next class.)
8
Shell Utilities % date % who % whoami % mail % pine (see chapter 20 of text for more mail details) % man
9
The UNIX File System (ch. 6) The File System is used to organize data. In UNIX, anything from which data can be taken/sent is called a file. ordinary file on disk printer keyboard Ordinary files are either of type: text – each character is stored as its ASCII value. binary – to be read only by computer.
10
Directories A directory in UNIX corresponds to a Folder in Windows (a place on the disk that can hold files and directories). When you are logged in to your account, you are always in some directory. That is called the current directory. Your “home” directory is the directory that you are in by default each time you login.
11
Directory Tree Directories have a hierarchical structure, represented by a Directory TREE. root / bin dev etc home tmp users1 ……. sokol …...
12
root / bin dev etc home tmp users1 ……. sokol …... courses forms papers CIS15 CIS23 CIS52 syllabus.htm hmwk1.htm
13
Pathnames A pathname is the address of a file or directory. It is the path of the file (or directory) in the Directory Tree. An absolute pathname is the path from the root to the specified file. e.g. /users1/sokol/courses/CIS15/syllabus.htm / represents the ROOT Note: in Windows, the backslash \ is used to separate levels of the tree. All web addressed, i.e. URL’s, use the forward slash as in UNIX.
14
Relative Pathname A relative pathname is the path in the directory tree beginning with the “current directory.” e.g. Suppose I am working in my home directory. I can refer to syllabus.htm as: courses/CIS15/syllabus.htm Or, if my current directory is CIS15, I can simply say syllabus.htm
15
Naming Files and Directories You do not have to use filename extensions, although you can if you wish. e.g. notes.txt myprogram.cpp UNIX is CASE SENSITIVE! Do NOT use spaces and special characters in your filenames (although. _, are allowed).
16
Some Shell Commands pwd prints working (or current) directory cd change directory [without arguments this brings you to home directory] ls lists files in current directory Many commands take options. Example: ls –la detailed list, and includes hidden files, which are those whose name begins with a. (e.g..profile,.login)
17
How can you create a file? 1. Copy or move another file 2. Redirect standard output 3. Use a Text Editor 4. Computer program writes to a file cp pathname1 pathname2 mv pathname1 pathname2
18
2. Redirection You can redirect the output of a command: e.g. ls > mylist spell > sperrs “funnels” the output to a file instead of screen. > erases file if it exists >> concatenates to end of existing file
19
3. Text Editor emacs vi pico Choose one of these and learn it since you have to be able to type up a text file in UNIX.
20
4. Computer program We will cover files in C++ in detail (Chapter 12 of text) so stay tuned…
21
Permissions The permissions of each file and directory can be viewed as a sequence of 10 bits. d stands for directory r read permission w write permission x execute permission drwxrwxrwx owner group public
22
Changing Permissions Your web page has to grant read and execute access to the public. How can you change permissions? use the chmod command examples: chmod 111001001 public_html chmod 711 public_html chmod a=rx mypage.html chmod a+r mp.html
23
More shell utilities for File Management cat more less pg lpr rm mkdir rmdir
24
Pipes You can send the output of one utility to the input of another utility using | example: cat pgm1 | more who | sort (note: redirection using > sends to a FILE, piping sends to another command.) Use the ; to group commands. example: ls; who; cd
25
The grep Command grep will search for a word inside of files or directories. It is extremely useful example grep December pgm1.cpp [this will list every occurrence of December in the file pgm1.cpp] OR grep December pgm*.cpp [this searches all files that begin with pgm and end with.cpp]
26
Wildcard character (*) Other examples of using the * ls *.cpp // this lists all of your.cpp programs that are in the current directory. cp *.output outfiles // copies all files ending with.output into a directory called outfiles
27
Processes (ch 11) Since UNIX is a multitasking system, a single user can also run several processes at once. You can either open different windows or you can run a process in the “background.” For example: %netscape & This will open netscape but give you the shell prompt back in your window.
28
Processes If you would like to see a list of all your active processes, use the command. Example: % ps PID TTY TIME CMD 25157 pts/11 00:00:00 ksh 25177 pts/11 00:00:00 tcsh 25206 pts/11 00:00:00 ps If you want to terminate a process: % kill 25177
29
Processes (cont) If a process is running in the foreground, and you want to kill it: ^ C (Ctrl+C) To suspend a process, use: ^ Z (Ctrl+Z) To resume the suspended process: % fg (for a foreground job) % bg (for a background job)
30
Symbols ~ /... & * > >> |
31
Programming under UNIX (ch32) 1 st level language = machine language (a binary sequence of 0’s and 1’s) 2 nd level language = assembly language Here, you can use English-like statements to represent machine level instructions. So, 1 assembly language instruction corresponds to one machine instruction. 3 rd level or “High” level languages easier to program portable
32
Program Translation Your high-level language program must be translated into machine language in order for it to be able to run. This is a 3 step process. 1. Preprocessing 2. Compilation 3. Linkage
33
1. Preprocessing A preprocessor reads through your program and replaces all preprocessor directives. A preprocessor directive is any line that begins with a # e.g. #include Notice that preprocessor directives are not C++ statements, and therefore do not terminate in a ;
34
2. Compile Compiling a program consists of translating a high level language to machine language, called object code. Object code is NOT executable yet… To compile your C++ program, type: % g++ -c mypgm.cpp or % CC –c mypgm.cpp NOTE: the –c option says to only compile. The CC are capital (lowercase cc is for C).
35
Compiling in UNIX When you compile your program, the compilation errors will display on the screen. You should open your program in a different window to correct the mistakes. If there are no compilation errors, a file called mypgm.o will be created. This is the object code of your program.
36
3. Linking There is still one more step to obtain your executable. It is called “linking.” Linking brings together all library functions that you included, all of your own functions, and your main function and an executable file is created. % g++ mypgm.o The same command is used for linking. [You can have linker errors, such as a function that is not found, or no main function, or multiply defined main’s.]
37
Running your program The output of the linker is an executable file called: a.out You can check that it has executable permission by typing _________. To run your program: % a.out Output will display on the screen. % a.out > myoutputfile Redirects your output to a file.
38
Compiling and Linking in 1 step You can invoke g++ to compile and link together, but this will be useful only for small programs. % g++ mypgm.cpp This will first compile and then link. Errors are labeled either as compiler or as linker errors.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.