LINUX System (English

Download Report

Transcript LINUX System (English

LINUX System : Lecture 2
(English-Only Lecture)
Bong-Soo Sohn
Assistant Professor
School of Computer Science and Engineering
Chung-Ang University
Acknowledgement : (i) wikipedia.org ,
(ii) http://www.doc.ic.ac.uk/~wjk/UnixIntro
Operating Systems

OS acts as an intermediary between user and HW

Resource Manager
 Allocates and manages system resources (CPU, Memory, Disks,
Networks, … )
 Efficient and fair use of the resources

Interface
 OS allows users and application programs to access system
resources
 Controls the execution of user programs accurately

Efficiently, Fairly, Safely(Accurately), Abstractly
Computer System Structure

HW – provides basic computing resources


CPU, memory, disk, …
OS Kernel


direct control of underlying HW
System call



Programming interface to the services provided by the
OS
The one program running at all times on the
computer is the kernel. Everything else is either a
system program (shipped with OS) or an application
program
Application programs



Define the ways in which the system resources are
used to solve user problems
executed thru shell/GUI.
Ex) word processor, video games, etc
Operating Systems

Functionality

Process Management


Memory Management








CPU scheduling : batch vs time-sharing
Memory allocation : determine what is in memory when?
Virtual memory : a technique that gives an application program the
impression that it has large contiguous working memory, while in fact it
is physically fragmented and may even overflow on to disk storage.
Disk and file system
Device driver : interface for communicating with HW devices
Networking : supports network protocols. (ex) TCP/IP
Security : authentication (login), authorization (file permission), …
UI : GUI (Graphical User Interface), CLI (Command Line Interface)
OS comes with application programs that provide an interface for
managing OS.
Storage Hierarchy

Register, Cache, Main memory, Secondary Storage (disks),
Magnetic tapes

Why hierarchical structure?
 Speed
 Cost
 Volatility

Caching
 Copying information into faster storage system.
 Faster storage checked first to determine if information is
there
 Cache<->main memory, main memory<->disk
 Important principle, performed at many levels in computer
OS Structures

Multiprogramming






a technique used to utilize maximum CPU time by running multiple
programs simultanously
Single user cannot keep CPU and I/O devices busy at all times.
Multiprogramming organizes jobs (code and data) so CPU always has
one to execute
One job is selected and run via job scheduler
When a running job has to wait for I/O, OS switches to another job
Multitasking (time-sharing)




CPU switches jobs so frequently that users can interact with each job
while it is running.
Creates interactive computing
Response time can be controlled
If processes don’t fit in memory, swapping moves them in and out to
run
Operating Systems

MS Windows



Most popular on desktop computers
Gaining popularity in servers.
UNIX/LINUX


Most popular in server environments
LINUX are gaining popularity on desktop PC.
UNIX System

has been popular for more than two decades

Portability


Written mostly in C + a few in assembly
language
Kernel size is small

Multi-user, multi-tasking environment
 Stability
 Powerful networking capabilities
 Free, open source code(LINUX)
Suitable for using as a server
UNIX History

Created by Ken Thompson et al. ( a researcher at AT&T Bell Lab)
 UNICS(1969) (shortened to UNIX later) : first version
 Released Fifth version of UNIX


kernel was rewritten in C, which was a big step forwards in terms of
system portability (1973)
LINUX






Developed by Linus Torvalds, a finnish undergrad student, in 1991
Free open source UNIX OS for PC
Open source code nature means any one can add features and correct
deficiencies.
Turned in to collaboration of hundreds of volunteer developers around
the world.
Several different distributions (e.g. Redhat, Debian, … etc)
Distribution comprises a prepackaged kernel, system utilities, GUI,
application programs
LINUX

Kernel




Shells / GUI : two forms of command input



Device driver support for various HW device
Advanced processor and memory management
Support different types of file system
Textual command line shells (e.g. C shell, … )
Graphical user interface (e.g. GNOME window manager)
System utilities


Virtually every UNIX system utilities were ported to LINUX
Include daemons


server program running as a background process
Application programs


Come with standard application programs
e.g. vi, emacs, xv, gcc/g++, xfig, latex, …
Cygwin
Login, Password

When connecting a UNIX system (locally or remotely)
login : will
password :

After successful login, you will get shell prompt where you
can give command input.
$

To logout, type exit


In GUI, it is trivial to login/logout
Password change
$ passwd
 Avoid dictionary words
Understanding /etc/passwd

/etc/passwd



Stores essential information required during login i.e.
user account information
It contains one entry per line for each user (or user
account) of the system. All fields are separated by a
colon (:) symbol. Total seven fields as follows
Username(1), password(2)-x means passwords are
stored in /etc/shadow, user ID(3), group ID(4), user ID
info(5), home directory(6), command/shell(7)
UNIX File System

Three types of UNIX files
 Ordinary files





Directory file


A file that has a list of other files and directories
Special file : I/O device


Contain text, data, program
Cannot contain other files or directories
Filename is not divided into name and extension officially
Up to 256 characters long
Devices : for easy access to HW device, a device is dealt with as a
file. e.g.) READ/WRITE for printer, network socket, …
Links
 A pointer to another file
 hard link : direct pointer
ex) $ln filename linkname
 soft(symbolic) link : indirect pointer ex) $ln –s filename
linkname
Directory in UNIX
< hierarchical tree structures >
Directory

Contains a list of files or directories and their
properties/locations


tree structure
a parent may have many childs, and a child can have only
one parent

Path
 absolute path :
 relative path :

/home/bongbong/a.txt
usr/bin/xv
Directory
 Home directory,
eg) cd ~bongbong
 Current directory : . , parent directory : ..
File Access

Example : /usr/bin/xv
1.
2.
3.
4.
Read root(/) directory
Find the location of “usr” from “/”
Read “usr” and find the location of “bin”
Read “bin” and find the location of “xv”
Commands for Files and Directories

pwd : prints [current] working directory
 cd : change directory
 mkdir , rmdir : create/remove a directory
 cp, mv, rm : copy, move, remove
 chmod : change permission of a file
 cat , more : prints text files
 man : manual for a command
 ls : list files
File properties

ls –l

type is a single character which is either 'd' (directory), '-' (ordinary file), 'l' (symbolic






link), 'b' (block-oriented device) or 'c' (character-oriented device).
permissions is a set of characters describing access rights. There are 9 permission
characters, describing 3 access types given to 3 user categories. The three access
types are read ('r'), write ('w') and execute ('x'), and the three users categories are
the user who owns the file, users in the group that the file belongs to and other users
(the general public). An 'r', 'w' or 'x' character means the corresponding permission
is present; a '-' means it is absent.
links refers to the number of filesystem links pointing to the file/directory owner is
usually the user who created the file or directory.
group denotes a collection of users who are allowed to access the file according to
the group access rights specified in the permissions field.
size is the length of a file, or the number of bytes used by the operating system to
store the list of files in a directory.
date is the date when the file or directory was last modified (written to). The -u
option display the time when the file was last accessed (read).
name is the name of the file or directory.
File Permission
Link

a pointer to another file
 Hard link to a file is indistinguishable
ex) $ln filename linkname
from the file itself

Soft link (symbolic link) provides indirect pointer or shortcut
to a file

ex) $ln –s filename linkname
$ ln -s hello.txt bye.txt
$ ls -l bye.txt
lrwxrwxrwx
1 will finance 13 bye.txt -> hello.txt
$

Soft link may point to a non-existing file
Wildcard : Specifying multiple files

UNIX shell processes this

‘?’ matches any one character
‘*’ matches any of zero or more characters
Characters enclosed in square brackets ('[' and ']') will match any filename that
has one of those characters in that position
A list of comma separated strings enclosed in curly braces ("{" and "}") will be
expanded as a Cartesian product with the surrounding characters



he* matches any filename beginning with 'he'.
 [m-z]*[a-l] matches any filename that begins with a letter
from 'm' to 'z' and ends in a letter from 'a' to 'l'.
 {/usr,}{/bin,/lib}/file expands to /usr/bin/file /usr/lib/file
/bin/file and /lib/file.
