Download FILE

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Unix time wikipedia , lookup

Linux adoption wikipedia , lookup

Library (computing) wikipedia , lookup

Berkeley Software Distribution wikipedia , lookup

Smallfoot wikipedia , lookup

Commodore DOS wikipedia , lookup

MTS system architecture wikipedia , lookup

Acorn MOS wikipedia , lookup

OS 2200 wikipedia , lookup

Unix wikipedia , lookup

Security-focused operating system wikipedia , lookup

RSTS/E wikipedia , lookup

Plan 9 from Bell Labs wikipedia , lookup

DNIX wikipedia , lookup

Burroughs MCP wikipedia , lookup

Comparison of command shells wikipedia , lookup

Spring (operating system) wikipedia , lookup

CP/M wikipedia , lookup

VS/9 wikipedia , lookup

Unix security wikipedia , lookup

Transcript
제01강 : Introduction to Linux Operatiing System
(I) Introduction to Linux Operating System
Kern Koh
Seoul National University
1
Course Description
•
•
•
•
•
•
•
•
•
[Linux programming]
First part of this course introduces students to the Linux programming. Most Linux manuals
are very cryptic and hence needs a gentle introduction. Students will be introduced to the
basic knowledge about (not necessarily all the commands themselves) Linux commands,
system calls, library and scripts - what feature is provided in each, and where to look for the
information about them, etc.
[Modern program development environment]
The second subject of this lecture is modern "program development environment" and
program development productivity. All the modern source codes are stored and distributed
in tens and hundreds of directories and files. All these files are combined and linked to make
one executable file. Modern computer architecture dictates such modular programming
practice. But such programming practise creates a host of new problems during program
development. Students are encouraged to understand the reason why such modular
programming method is needed. Regular expression and tags file will be taught as a means
of helping source code browsing. Make and SCCS commands are explained as a way of
managing source codes and as a way of minimizing build time. Other important tools and
utilities such as grep, find, ctags etc will be also taught.
[Linux Kernel Internal]
Third subject of this lecture is Linux kernel internal. This part begins from the kernel overall
architecture, several important concepts exported by kernel such as file descriptor,
superblock, inode, buffer cache, fsck etc. We will first read UNIX source code then
introduce Linux source code.
In sum, much emphasis of this lecture is on the practice, not just the theory and concepts of
Linux. The students are greatly encouraged to practise a lot of commands, make scripts,
manage system, and study source code on Linux platform. All the lab work will be carried
2
out on recent Linux operating system. Following books are recommended as text books and
references:
Outline
• Interface to Operating System
– Command, system call, script, daemon
– shell variable, IPC, Web, CGI etc
• Modern Program Development
– make, tags, include, DLL, RPM etc
– testing & debugging
• UNIX/Linux kernel Internal Design
– UNIX – Lion’s book & code
– Linux – Love’s book & code
• Always have Linux machine on-line besides you
– We emphasize practice in this class
3
References
(1) If you are a Beginner:
o Christian, The UNIX Operating System, 2nd Ed, Wiley.
(2) To learn more about Commands:
UNIX Power Tools, An O'Reilly & Associates/Random House Book.
(3) If you want to be an advanced user
o Anderson, The UNIX C Shell Field Guide, Prentice Hall
o Newham & Rosenblatt, Learning the BASH shell, O'Reilly
(4) For function call interface (library, system calls)
Stevens, Advanced Programming in UNIX, Addison Wesley.
(5) If you want a textbook about Operating System
o Silberschatz et. al., Applied Operating System Concepts, John Wiley & Son
(6) For kernel source code
o John Lions, Lions' Commentary on Unix : With Source Code,
o Robert Love, Linux Kernel Development, Developer’s Library.
4
Homework
• Login to Linux machine
• Use vi editor and type in C program
• We assume you are familiar with C & vi editor.
main()
{
printf(“Hello\n”);
}
• Name it “Hello.c”
• Compile
(use “gcc Hello.c”)
• Check if a.out is created
(use “ls”)
• Run it
(just say “./a.out”)
5
History of UNIX
• UNIX was designed for
– Timesharing (Interactive) System
• Use terminals (not card reader, printer)
• Response time oriented * (not Throughput oriented)
• Main use:
– Program Development
– Office Automation
– Multiuser system
• Portable OS
• by Bell Laboratories (AT&T)
* 747 -- throughput oriented (batch -- wait until many arrives) – HW important
taxi -- response time oriented (as soon as a customer arrives) --- customer important
6
Portability (移植可能)
1. Every programs needs OS (OS manages HW)
2. Before, hardware was expensive (no IC)
3. OS runs frequently  OS must be efficient
4. Code OS with assembler  CPU dependent
-------------------------------------------------------1. UNIX was coded in C language
2. Unix can be ported to any CPU * (with C**)
3. Unix can talk with any HW(running UNIX)
*
**
Other
OS
UNIX
No more learning, conversion needed when HW changes.
Language porting is easier than OS porting
7
Terminology
• utility
– command, disk resident part of OS (loaded on demand),
– “program”(next page)
• kernel
– memory resident part of OS, just plain C program.
• shell
– A special utility. It’s mission is Job Control
– reads keyboard input & execute command (interpreter)
– UNIX interface to user,
• file
– “named collection of information”
– “sequence of bytes”, no other restrictions (eg record, block)
– I/O devices are treated as files (special files, try ls /dev)
• standard file
– standard output: screen
– standard error:
error message
– standard input:
keyboard
8
Software Concept
• Hardware supports only 3-level objects:
[1] Instruction (機械語)
[2] Function (函數)
[ADD SUB JUMP …..…]
[sin() open() print() ..]
• function invocation  push a frame into stack
return address, local variables, …
[3] Process
•
•
•
•
[binary, a.out, a.EXE,…]
eg shell, editor, word, kernel, …
Program Image:
functions, variables
HW resource:
keyboard, screen, memory, …
SW resource:
files, lock, …
9
Terminology (用語)
main()
Function
(函數)
printf()
sin()
Process
(a.out, program)
STACK
10
• Every SW object -- map to these three
[1] Instruction
(機械語)
[2] Function
(函數)
[3] Process
(program, binary, a.out)
Editor
game
Shell
Library
System call
Daemon (server)
Window
ftp
Tcp/ip
Web server
macro
11
• Upper/Lower case
– ‘Boy’ and ‘boy’ are different in UNIX!
• Login
– type username, password (multi-user system)
– ask system administrator to get them
• (shell) prompt
– %, $, …
– prompt appears  “shell is ready to accept next command”
• file names
– absolute pathname:
– relative pathname:
/a/b/c starts from root
x/y starts from current directory
12
• Suffix
.c
.h
.f
.s
c source
header file
fortran source
asm source
• special characters
–
–
–
–
kill
EOF
stop
backspace
^c
^d
^s
^h
13
Manual
• Manual volumes
(1) commands
(2) system call
(3) library functions
• try man cat, man ls
– bold
–[]
– file
as it is
option
name of the file
–…
repeat
• Exercise
rm [-fri] file …
rm -fr
rm -f -r
f2 f3
f1
(o)
(x)
mail [-r][-q][-p][-f file]
mail -r -p
(o)
mail -rp
(x)
try “man 1 intro”, … , “man 4 intro”, …
14
What are sections 4 - 9 about?
$ man cat
CAT(1)
User Commands
CAT(1)
NAME
cat - concatenate files and print on the standard output
SYNOPSIS
cat [OPTION] [FILE]...
DESCRIPTION
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all
equivalent to -vET
-b, --number-nonblank
number nonblank output lines
-e
equivalent to -vE
15
command | sys call | library
CAT(1)
User Commands
CAT(1)
NAME
cat - concatenate files and print on the standard output
One Line Summary
[]
SYNOPSIS
cat [OPTION] [FILE]... FILE
…
else
DESCRIPTION
--- option
--- file
--- repeat
--- as it is
Try “ whatis
cat”
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all
equivalent to -vET
-b, --number-nonblank
number nonblank output lines
-e
equivalent to -vE
16
Manual
• Manual volumes
(1) commands
(2) system call
(3) library functions
• try man cat, man ls
– bold
–[]
– file
as it is
option
name of the file
–…
repeat
• Exercise
rm [-fri] file …
rm -fr
rm -f -r
f2 f3
f1
(o)
(x)
mail [-r][-q][-p][-f file]
mail -r -p
(o)
mail -rp
(x)
try “man 1 intro”, … , “man 4 intro”, …
17
What are sections 4 - 9?
CAT(1)
User Commands
CAT(1)
NAME
cat - concatenate files and print on the standard output
SYNOPSIS
cat [OPTION] [FILE]...
DESCRIPTION
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all
equivalent to -vET
if you don’t provide file name
-b, --number-nonblank
number nonblank output lines
-e
equivalent to -vE
18
man cat
• SYNOPSIS
– cat [OPTION] [FILE]...
• need to provide FILE(s)
– read until EOF (ctrl-D is EOF)
• What if no FILE is provided?
– (standard input  standard output) until EOF (ctrl-D is EOF)
$ cat
1
(user types)
1
(cat command outputs to screen)
2
(user types)
2
(cat command outputs to screen)
---------- until when? ---------------
ctrl-D
$
19
man bash
(Command Line Interpreter)
• SYNOPSIS bash [options] [file]
• bash needs FILE
– read until EOF (ctrl-D is EOF)
– eg bash FILE (read each line & execute it)
–
“FILE” is script file (text, whose line is command)
–
“bash” is interpreter
• What if FILE is NOT provided?
– bash reads from standard input until EOF (ctrl-D)
$ bash
$ command1
$ command2 …
(ctrl-d) 
no FILE given. So bash reads from keyboard.
user types command1 at keyboard. ….
bash continue reading keyboard until EOF
bash reached EOF at keyboard.
20
script
$ bash hello
 Now we provide file called hello
hello’s content is
date
date
date
• hello is an example of script file
• Try another thing ….
• At the shell prompt, try:
$ ./hello
 bash reads lines in hello, executes
• It looks the same as a command
• Command can be either (a.out) or (script)
•
[binary] [text file]
21
• When you know the name of command (function)
– man rm
– whatis rm (one line summary)
• When you don’t know the name of command,
but you know what it does
– man -k delete
– apropos delete
Ex
apropos concatenate
apropos shutdown
22
$ whatis cat
cat
(1) - concatenate files and print on the standard output
$ apropos concatenate
cat
(1) - concatenate files and print on the standard output
ospent
(1) - Concatenate entities
strcat
(3) - concatenate two strings
strncat [strcat] (3) - concatenate two strings
tac
(1) - concatenate and print files in reverse
wcscat
(3) - concatenate two wide-character strings
wcsncat
(3) - concatenate two wide-character strings
$
23
Multi-user vs Single-user
• Linux
• Protection - Yes
• Resource – 最大 節約
– Text mode (CUI)*
– Total silent
• eg vi
* CUI: Character User Interface
• Windows
• Protection - Little
• Resource – 最大 使用
– Window, GUI
– Shows everything
•
•
•
•
History
State
Command
Option
• eg word ….
* GUI:
Graphical User Interface
24
User Interface (OS)
GUI - Windows
CUI - Linux
$_
menu
active processes
(Programs in disk) (loaded into memory)
man
Command
ps
Command
25
$ ps -A
PID TTY
1
?
2
?
3
?
4
?
5
?
6
?
7
?
8
?
9
?
24
?
| more
TIME
00:00:01
00:00:01
00:00:00
00:00:01
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
CMD
init
migration/
ksoftirqd/0
migration/1
ksoftirqd/1
events/0
events/1
khelper
kacpid
kblockd/0
$ ls /bin
arch
date
gettext mkdir
ash
dd
grep
mknod
ash.
static
df
gtar
awk
dmesg gunzip more
basename gzip
mount rview
bash
doexec hostname mt
bash2
igawk mv
setfont
bsh
ipcalc
netstat setserial
rm
touch
rmdir
tracepath
mktemp tracepath6
rvi
traceroute
traceroute6
sed
true
umount
uname
26
User Interface (editor)
CUI – vi
GUI - word
:_
27