why unix? superior initial design –multi-user, multiprogramming, protected mode, many support many...
Post on 22-Dec-2015
215 views
TRANSCRIPT
Why UNIX?• Superior Initial Design
– Multi-user, Multiprogramming, Protected mode, Many Support many Devices
– Written to optimize the use of memory and maximize efficiency– Remained consistent to its original design– Not driven by profit motives– Source code compatible across platforms
• Other Operating Systems– IBM MVS: initially designed for a batch punch card environment
with proprietary monitors– DOS: initially ran on very single user, limited memory computers.
Multiprogramming was added on as an afterthought.
UNIX downside: Geared for power users using a command line interface
OS Benchmarks (A bit dated)
OS Loop Write Seek Read
FreeBSD 3.0 21 7.3 17.8
Linux 3.0 14 16.3 18.2
SCO (Unix) 2.4 34 16.6 24.5
Window 3.1 6.2 190.4 26.6 56.8
Linux 3.0 15.97 11.98 13.95
Window 95 6.65 125.94 11.79 47.45
Why C• Fast
– Designed to produce code nearly as fast as assembly code.
– Designed to be able to support Operating System development.
• Portable– Recompiling will cause code to work across platforms– POSIX provides a standard OS interface
• Powerful: Able to perform low level functions• Small: C code is smaller than other high level languages• Popular: C is a very popular programming language
Downside: With power comes danger. You have to know what you are doingDownside: Not object oriented. You have to be disciplined
Language Comparisons
• Assembly – small, fast, not portable• C – almost as small and fast, portable• Fortran, Pascal – Slower, specific purpose• C++, PL1 – Complex, larger and slower• Java, Basic – Byte oriented, even slower• Scripting languages – interpreted, slow
Note: JIT technology makes byte code languages more speed competitive
Executable Memory
C 3811 820kb
C++ 18033 1052 kb
Memory Use Example
History1. 1960s was the era of batch processing
• Punch cards, paper tape, Magnetic tape• System operators
2. Multics attempt at an OS• general purpose, multi user, time sharing• project died: technology of the time could not support the effort
3. 1969 – AT&T Bell Labs (Ken Thompson) writes first version of Unix in BCPL
4. 1972 – Dennis Ritchie creates "C", UNIX written in C5. 1984 – Richard Stallman starts the free Software
Foundation (FSF) with goal to develop a free version of UNIX (GNU – Not Unix)
6. 1991 – Linus Torvalds writes Linux Kernel (GNU+ Kernel)7. 2000 – User Friendly UNIX (Mac OS X) interface8. Academia likes UNIX based systems; they are free
"Pigs get fat, Hogs get slaughtered"• AT&T develops UNIX at Bell Labs• Berkeley gets a copy and makes enhancements• AT&T commercializes UNIX and makes it proprietary• Richard Stallman was an AI researcher at MIT
– He objected to the trend towards proprietary software. – He formed GNU (GNU's not UNIX) – GNU to replace the UNIX shells and utilities
• Berkeley objected to AT&T licenses, and developed BSD• Andrew Tananbaum created Minimal Unix (MINIX)• Linus Torvalds (CS student) coded the Linux kernel• Open source produces lots of high quality software• No open source movement implies no Internet
UNIX Structure• The Kernel is the part of
the OS always in memory• Includes
– File system– Device manager– memory management– process scheduler– well defined interface
• GUI: Point and click (many wrappers to the X-Window interface)
• Shells: command line
Users
GUI's Shells
Hardware
Kernel
Shells• A command-line interface that allows users to directly
access operating system capabilities
• There are more than one shells possible in UNIX: csh, bash, tsch, ksh, etc
• Text only commands, without using the mouse. “Finger never leaves keyboard.”
• Groups of commands can be strung together in unique ways to make difficult tasks possible, without creating specialized programs
Comparison between shells
• sh (bourne shell)– small– good scripting capability– popular with system
administrators
• csh (c-shell)– extends sh– uses a c-like syntax– created by Bill Joy– popular with UNIX
users
• bash – "bourne-again" shell– extends sh with some
features form csh– The linux default– We will use bash
• tcsh– extension of csh
Where do we find a UNIX
• Virtual “Linux” servers provided by IT– Log In (Putty program) creating a secure shell (SSH)
with your standard username/password– See a shell prompt (>, &, $, etc.)– Type your command– The shell will execute the command and return with
another prompt• Mac/OS provides a UNIX-like system• You can install LINUX on windows systems
using a dual boot• You can install CYGWIN on a windows system
The Shell language• Remember
– Shell commands are case sensitive– The general form of commands are
• Syntax: <cmdName> [-flags] [args]
Note: <> indicates something that is required, [] indicates something that is optional
Example: >echo –n I love UNIX1. > is the shell prompt2. echo is a UNIX command 3. -n is a flag4. I love UNIX are three arguments (space separators). 5. This command outputs the arguments: I love UNIX6. The –n inhibits a new line after the output
Display prompt Enter command from command line execute/process command
Some basic commands>clearclears the screen>wholists the users currently logged in>logout or >exit (Exit is recursive)exit the shell, and wait for another log in>echo whatever I wantoutputs the data to the right>man <manName>display UNIX manual for the command, manName
Note: Use ctrl c to abort commands (abbreviation ^c)
Shell Variables• Example: $<varName>
• The shell has some built in variables$TERM represents the terminal type
$SHELL represents which shell is active
$USER user name
$PATH places to look for executables
• What do you suppose the following does?>echo I have a $TERM with $SHELL shell
• Printenv outputs environment variables, set outputs environment and shell variables
Environment variables: those common to all shells
The File System• The file system is a hierarchical tree structure of
regular files and directories (folders)
• Within the file system, there are individual files for programs and data, and directories that contain other files
• Directory Examples– The root directory is / (analogous to c: on Windows)
– A users home directory is ~– /faculty/harveyd/public_html/classes/cs367/ppt
Important: File names are case sensitive. Name only with numbers, letters, and underscores. Punctuation characters can conflict with shell commands
Explore Linux (partial directory list)
• /root : super user’s home directory
• / : system root directory (like Window’s c: )
• /tmp : temporary sharable files available to all users
• /bin : executables required for kernel
• /sbin : executables requiring super user access
• /etc : system configuration files
• /var : system changeable files
• /opt : optional installs
• /home : contains all user’s home directories
• /mnt or /media : mount points
• /dev : system devices
• /boot : contains linux kernel
• /usr/bin : applications coming with distribution
• /usr/sbin : applications installed later
File Commands>cdChange directory
Example using 'absolute' pathnames (cumbersome)/faculty/harveyd/public_html or ~/dir1/dir2/dir3
Example using relative pathnames>cd ~ (go to the users home directory)>cd public_html (public_html directory relative to working directory)>cd .. (change to parent directory above the working directory)
>pwdDisplays the 'absolute' pathname from the root with '/' separators
Note: >cd . refers to the current yNote: The shell variable $PWD contains what pwd displays
more/ less and cat commands>cat <filename>Display the contents of the file
Problem: too much to displaySolution: >more fileName
Explanation: more is a program that displays one page at a time and then waits for you to enter a commandExplanation: less is an enhancement to more (“less is more”)
Note: The man command uses more commands, and displays a page at a time
Command Action
Space or f or page down
Go forward one page
b or page up Go back one page
/keyword Find first page with keyword
/ or n Find next occurrence of keyword
Up or down arrows
Move up or down one line
return Go forward one line
q Quit
List contents of a directory• List all files that match the pattern
>ls <pattern> … <pattern>• A pattern can be: a combination of letters, asterisks, and
question marks. – Asterisks mean any sequence of characters– ? is any single character– Example: *cat?dog* refers to any file name having the word cat
separated by one character frm the word dog anywhere in the file name
– [abc] means any single character between the brackets (but cannot use / or . characters in the list.
• Flags (refer to the man command for a complete list>ls –l lists files in a long format>ls –a lists all files including hidden ones (starting with a period)>ls –al or ls –a –l lists files combining the flags
man <anycommand> gives information how to use it
File links• Hard link (ln myFile myLink)– Points directory to the file’s data– We can delete either the file or the link– The actual data is removed when the last link is removed– It is illegal to link to directories
• Symbolic links (ln –s myfile mySymbolicLink)
– References file’s directory entry by name– myfile does not even need to exist (link broken)– Deleting a link, never deletes the file– Equivalent to Windows shortcuts– Circular links cause errors when access is attempted
Additional Commands• Rename file: >mv <oldName> <newName>• Copy file: >cp <file> .. <file> <destination>• Secure copy to remote computer:
– scp <file>...<file><destination– Example: scp cat.c [email protected]:drop
• Delete file: >rm <file> .. <file>• Make a directory: >mkdir <directory>• Execute allowed as superuser: >sudo command• Which version of a command: >which <command>• Type of command : >type <command>• Who’s logged in: >whoami• Detailed documentation: >man <command>• Brief description: >whatis <command>• Description of shell built-in commands: info <command>
Note: Most commands have many flags. For example –r is often used to access all subdirectories (ex: rm –r <dir>
More on flags• cp –vfirl or rm –rifv --help
– Note that we can string multiple flags together– v = verbose, f = force, i = interactive, r = recursive, l =
link instead of copy– Most also have long english type versions preceded
by double dashes. For example: cp –recursive
• ls –dlaRr– d = directory (not contents), l = long form, a = all files,
R = recursive, r = reverse order
• mkdir –p (create parent directories if not found)• man –k term (same as apropos) to find all
entries related to term