Linux Overview
Linux Overview
Linux
1
Features of modern OS
To facilitate easy,
efficient, fair, orderly,
and secure use of
resources
– Provide a user
interface
– Organize files on disk
– Allocating resource to
different users with
security control
– Co-ordinate programs
to work with devices
and other programs
2
Linux
Development of Linux
3
Before Linux
– In 80’s, Microsoft’s DOS was the dominated OS for PC
– single-user, single-process system
– Apple MAC is better, but expensive
– UNIX is much better, but much much expensive. Only for
minicomputer for commercial applications
– People was looking for a UNIX based system, which is
cheaper and can run on PC
– Both DOS, MAC and UNIX are proprietary, i.e., the source
code of their kernel is protected
– No modification is possible without paying high license
fees
4
GNU project
– Established in 1984 by Richard Stallman, who believes that
software should be free from restrictions against copying or
modification in order to make better and efficient computer
programs
– GNU is a recursive acronym for “GNU's Not Unix”
– Aim at developing a complete Unix-like operating system which
is free for copying and modification
– Companies make their money by maintaining and distributing
the software, e.g. optimally packaging the software with different
tools (Redhat, Slackware, Mandrake, SuSE, etc)
– Stallman built the first free GNU C Compiler in 1991. But still, an
OS was yet to be developed
5
Beginning of Linux
– A famous professor Andrew Tanenbaum developed
Minix, a simplified version of UNIX that runs on PC
– Minix is for class teaching only. No intention for
commercial use
– In Sept 1991, Linus Torvalds, a second year student
of Computer Science at the University of Helsinki,
developed the preliminary kernel of Linux, known as
Linux version 0.0.1
– It was put to the Internet and received
enormous response from worldwide
software developers
– By December came version 0.10. Still
6 Linux was little more than in skeletal form.
Confrontation and Development
– Message from Professor Andrew Tanenbaum
– " I still maintain the point that designing a monolithic kernel in 1991 is a
fundamental error. Be thankful you are not my
student. You would not get a high grade for such a design :-)"
(Andrew Tanenbaum to Linus Torvalds)
– "Linux is obsolete".
(Remark made by Andrew Tanenbaum)
– But work went on. Soon more than a hundred people joined the Linux
camp. Then thousands. Then hundreds of thousands
– It was licensed under GNU General Public License, thus ensuring
that the source codes will be free for all to copy, study and to change.
7
Linux Today
– Linux has been used for many computing platforms
– PC, PDA, Supercomputer,…
– Current kernel version 2.6.13
– Not only character user interface but graphical user interface, thanks to
the X-Window technology
– Commercial vendors moved in Linux itself to provide freely distributed
code. They make their money by compiling up various software and
gathering them in a distributable format
– Red Hat, Slackware, etc
– Chinese distribution of Linux also appeared in Taiwan and China - CLE,
Red Flag Linux
8
Linux Pros and Cons
Advantages over Windows
– It's almost free to relatively inexpensive
– Source code is included
– Bugs are fixed quickly and help is readily available through the vast
support in Internet
– Linux is more stable than Windows
– Linux is truly multi-user and multi-tasking
– multiuser: OS that can simultaneously serve a number of users
– multitasking: OS that can simultaneously execute a number of programs
– Linux runs on equipment that other operating systems consider too
underpowered, e.g. 386 systems, PDA, etc
9
Linux Pros and Cons (Cont)
Disadvantages compared with Windows
– Isn't as popular as Windows
– No one commercial company is responsible for Linux
– Linux is relatively hard to install, learn and use
11
Applications: Compilers, word processors, X-based GUI
AUI
LINUX Shell: Bourne Again (bash), TC, Z, etc.
Language libraries
API System call interface
12
Kernel
– The part of an OS where the real work is done
System call interface
– Comprise a set of functions (often known as Application
Progarmmer’s Interface API) that can be used by the applications and
library routines to use the services provided by the kernel
13
File Management
– Control the creation, removal of files and provide directory
maintenance
– For a multiuser system, every user should have its own right to
access files and directories
Process Management
– For a multitask system, multiple programs can be executed simultaneously in the
system
– When a program starts to execute, it becomes a process
– The same program executing at two different times will become two different
processes
– Kernel manages processes in terms of creating, suspending, and terminating them
– A process is protected from other processes and can communicate with the others
14
Memory management
– Memory in a computer is divided into main memory
(RAM) and secondary storage (usually refer to hard disk)
– Memory is small in capacity but fast in speed, and hard
disk is vice versa
– Data that are not currently used should be saved to hard
disk first, while data that are urgently needed should be
retrieved and stored in RAM
– The mechanism is referred as memory management
Device drivers
– Interfaces between the kernel and the BIOS
– Different device has different driver
15
Linux
User interface
16
Linux User Login
Linux is a multiuser OS
Allow multiple users to use the resource of a computer at
the same time
Every user needs to login the system with the password
provided to identify their right in using the resource
Require for both client-server based system or desktop
Linux Paul
Server Peter Mary
Peter: admin
Paul : general
Mary : intruder Client-server based
: system
17
Linux User Interface
Traditional Linux (Unix also) uses command-
driven interface (or text-based interface)
– User needs to type lines of command to instruct the
computer to work, similar to DOS
– Advantage: fast in speed. Very few resource is
required for its implementation
– Disadvantages: user needs to type, hence can
easily make error. Besides, user needs to memorize
all commands
– Suitable for expert users and for the systems that
interaction with user is not frequent, such as servers
18
By adopting the X-Window technology, graphical user interface
(GUI) is available for Linux:
– Uses pointing devices (e.g. mouse) to control the system,
similar to Microsoft’s Windows
– Provide menu-driven and/or icon-driven interfaces
– menu-driven: user is provided with a menu of choices.
Each choice refers to a particular task
– icon-driven: tasks are represented by pictures (icon) and
shown to user. Click on an icon invokes one task
– Advantages: No need to memorize commands. Always
select task from menus or icons
– Disadvantages: Slow and require certain resource for its
implementation
– Suitable for general users and systems, such as PC
19
•• A typical Linux GUI based on
A typical Linux GUI based on
GNOME
GNOME
•• Similar to Microsoft’s Windows,
Similar to Microsoft’s Windows,
however,
however,different
differentwindow
windowsystems
systemscancan
be
bechosen
chosen(e.g.
(e.g.GNOME,
GNOME,KDE,
KDE,etc)
etc)
20
Linux
Linuxtext-based
text-basedinterface
interface
23
Linux
File management
24
Linux File Management
InLinux, file is defined as simply the thing that
deals with a sequence of bytes
Hence everything are files
– An ordinary file is a file; a directory is also file; a network
card, a hard disk, any device are also files since they
deal with a sequence of bytes
Linux supports five types of files
– simple/ordinary file (text file, c++ file, etc)
– directory
– symbolic (soft) link
– special file (device)
– named pipe (FIFO)
25
The concept of simple file and
directory is similar to DOS
27
ENG224
INFORMATION TECHNOLOGY – Part I
2. Operating System Case Study: Linux
Command that sets a
symbolic link to a file
called CUI to anotherCUI
root / directories
file
… dlun guest bin lib local
fd hd hd group passwd
30
Root Directory ( / )
– Top of the file system. Similar to \ in DOS
/bin
– Contain the binary (executable code) of most essential
Linux commands, e.g. bash, cat, cp, ln, ls, etc.
/boot
– Contain all the files needed to boot the Linux system,
including the binary of the Linux kernel. E.g., on Red
Hat Linux 6.1, the kernel is in /boot/vmlinux-2.2.5-15 file
/dev
– Contain the special files for devices, e.g. fd0, hd0, etc.
31
/etc
– Contain host-specific files and directories, e.g.
information about system configuration
– /etc/passwd
– This file contains login information of users in the
system
– For every user, one line of record is stored in the
following format:
32
E.g. davis:x:134:105:James A Davis:/home/davis:/bin/bash
– davis : login name
– x : means that it is a dummy password. The encrypted password
is stored in /etc/shadow. This field can also be used to store the
actual encrypted password. In any case, the original
(unencrypted) password cannot be seen by anyone, including
the administrator
– 134 : a user id given to that user. Range from 0 to 65535. 0 is
assigned to super-user. 1 to 99 are reserved
– 105 : a group id given to that user to indicate which group he
belongs to. Range from 0 to 65535. 0 to 99 reserved
– James A Davis : user info, usually user’s full name
– /home/davis : home directory of the user
– /bin/bash : the location of the shell the user is using
33
/home
– Contain the home directories of every user in the
system, e.g. dlun, guest, etc
/lib
– Store all essential libraries for different language
compilers
/lost+found
– Contain all the files on the system not connected to
any directory.
– System administrator should determine the fate of
the files in this directory
34
/mnt
– Use by system administrator to mount file systems
temporarily by using the mount command
– Before using any devices, they have to be mounted to the
system for registration
– For example, after mounting a CD-ROM, the file system in
it will be mapped to /mnt/cdrom directory
– User can then read and write files in the CD-ROM by
accessing this directory
– Similar to mapping a drive letter to a CD-ROM in Windows
– Different from the special file in /dev. Special file is only a
place where data of the CD-ROM is transferred or stored.
No file system concept
35
/opt
– Use to install add-on software packages, e.g. star office,
etc.
/proc
– Contain process and system information
/root
– Home directory of the user root, usually the administrator
/sbin
– The directories /sbin, /usr/sbin, and /usr/local/sbin
contain system administration tools, utilities and general
root only commands, such as halt, reboot and shutdown
36
/tmp
– Contain temporary files. Usually files in this directory will
be deleted from time to time to avoid the system fills with
temp files
/usr
– One of the largest sections of the Linux file system
– Contain read-only data that are shared between various
users, e.g. the manual pages needed for the command
man. Stored in /usr/man direcrtory
/var
– Contain data that keeps on changing as the system is
running. E.g. /var/spool/mail directory keeps the mail of
user
37
Linux File Access Privilege
Linux is a multiuser system, the files of all users
are stored in a single file structure
Mechanism is required to restrict one user to
access the files of another user, if he is not
supposed to
User can impose access permission to each file to
restrict its access
The term “access permission” refers to
– read permission
– write permission
– execute permission
38
ENG224
INFORMATION TECHNOLOGY – Part I
2. Operating System Case Study: Linux
39
File last
Hard Owner Owner’s modified date
link no group
41
The access permission of a file or directory can
be changed by using the command
42
temp does not have execution right
44
Formatted Disk
Sector Density of data is
Track higher for inner tracks
than outer tracks
45
Must read or write whole sector at a time
OS allocates groups of sectors called cluster to files
Files smaller than the cluster will still be allocated the whole
cluster, but the rest left unused
In Linux, every file is associated with an inode that records its
location in the disk
The inode of all files are put together in a data structure called
inode table
In the directory, every file is associated with a inode number that
points to an entry of the inode table
46
Contents of the directory /home/dlun
1076 …
2083 …
13059 lab1.c
17488 lab2.c
18995 lab3.c
Number of links
Lab3.c
: File mode Lab2.c
User ID
Time created Lab1.c
Time last updated
: :
Location on disk
47
Linux
Process management
48
Linux Process Management
Linux is a multitasking system
Multiple programs can be executed at the same time
Ultimately, a program needs to be executed by a CPU
If there is only one CPU, how multiple programs can
be executed at the same time?
By time sharing
That is, all programs are claimed to be executing. In
fact, most of them are waiting for the CPU
49
A program that is claimed to be executing is
called a process
For a multitasking system, a process has at least
the following three states:
Start Finish
execution Ready Running
execution
Sleeping
50
Ready state
– All processes that are ready to execute but without the CPU are at the
ready state
– If there is only 1 CPU in the system, all processes except one are at the
ready state
Running state
– The process that actually possesses the CPU is at the running state
– If there is only 1 CPU in the system, at most there is only one process is at
the running state
Sleeping state
– The process that is waiting for other resources, e.g. I/O, is at the sleeping
state
51
Processes will alternatively get into the CPU one after the other (called the round
robin scheme)
A process will be “in” a CPU for a very short time (quantum)
– For Linux, each quantum is about 100msec
At the time that a process is selected to be “in” the CPU
– It goes from ready state to running state
After that, it will be swapped out
– It goes from running state back to ready state
Or it may due to the waiting of an I/O device, e.g. mouse
– It goes from running state to sleeping state
When obtaining the required resource
– It goes from sleeping state to ready state
52
ready C A B C A B
B A B A B C A B C A C A B A
running A B A B A B C A B C A C A B
Time
C Executes
B Sleeps
B Awakes
C Terminates
B B
sleep
53
The mechanism to determine which process should “get
into” the CPU is called Process scheduling
For example,
Program A Actual sequence of operations
a ->10
Set variable a to 10
b ->0
Set variable b to 0 c ->a+b
b ->c
Repeat 5 times the following
c ->a+b
{ b ->c
c ->a+b
Set variable c to a+b
b ->c
Set variable b to c c ->a+b
b ->c
} c ->a+b
Print out the value of b b ->c
54 Print out b
Actual sequence of operations
d ->0
Program B User ->e
f ->d+e
Set variable d to 0 d ->f
Repeat 5 times the following User ->e
f ->d+e
{ d ->f
User ->e
Ask user to enter variable e
f ->d+e
Set variable f =d+e d ->f
User ->e
Set variable d =f f ->d+e
} d ->f
User ->e
Print out the value of d f ->d+e
d ->f
Print out d
55
Program A and B will be at the running state
alternatively, depends on the quantum size and the
availability of the required resource
a ->10 c ->a+b
b ->0 Program b ->c
c ->a+b A Print out b
b ->c f ->d+e
Quantum c ->a+b
finishes d ->f
end d ->0 User ->e
Waiting for User ->e f ->d+e
b ->c d ->f
user input c ->a+b User ->e
b ->c f ->d+e
c ->a+b d ->f
Quantum b ->c User ->e
end f ->d+e
Program f ->d+e
d ->f B d ->f
Waiting for
56
User ->e finishes Print out d
user input
Terminal pts/0 has the editor vi
running
Terminal pts/1 is
executing ps to see
the processes of both
terminals
59
A process can be forced to terminate by using
the command kill -9 PID