Sie sind auf Seite 1von 19

Lecture 2: UNIX STRUCTURE

Asoc. Prof. Guntis Barzdins


Asist. Girts Folkmanis
University of Latvia
Sept 24, 2004
The Unix Architecture
Essential Unix Architecture
Applications

System Libraries (libc)

System Call Interface

I/O Related Process Related


Modules

File Systems Scheduler


Networking Memory Management
Device Drivers IPC

Architecture-Dependent Code

Hardware
The Users

shells and commands


compilers & interpreters
system libraries

system call interface to the kernel

signals file system CPU scheduling


terminal handling swapping page replacement
char I/O system block I/O system demand paging
terminal drivers disk & tape drivers virtual memory

kernel interface to the hardware


terminal controllers device controllers memory controllers
terminals disks & tapes physical memory
System Calls
 System calls for low level file I/O  System Calls for IPC
 creat(name, permissions)  pipe(fildes)
 open(name, mode)  dup(fd)
 close(fd)
 unlink(fd)
 read(fd, buffer, n_to_read)
 write(fd, buffer, n_to_write)
 lseek(fd, offest, whence)  Total ~270 System Calls in Linux kernel v2.6
 Portable Operating System Interface (POSIX)
 System Calls for process control  ISO/IEC 9945
 fork()  IEEE 1003
 wait()  Single UNIX Specification (SUS)
 execl(), execlp(), execv(), execvp()  Linux Standard Base
 exit()
 signal(sig, handler)
 kill(sig, pid)
Processes
kernel Process 0: Kernel bootstrap. Start process 1.
kernal mode
user mode Process 1: create processes to allow login.
/etc/init

fork fork
inetd exec exec
lpd
/etc/getty /etc/getty condition terminal for login
httpd
exec exec
/bin/login /bin/login check password
exec exec
shell shell command interpreter
Parts of process memory structure
•user-id switches on system call
•open files (trap, software interrupt)
•saved register states
•environment

Stack frames of
invoced functions

•Initialised data arena/heap


•Non-initialised data •malloc

Program code

bash$ size testhand2


92763 + 7564 + 2320 = 102647
Big Picture: Another look
kernel memory

process structure

kernel stack/u area kernel stack/u area kernel stack/u area


Stack Stack Stack

Data Data Data


Text (shared) Text (shared) Text (shared)
Process states
Mode, Space and Context
Privileged
mode user kernel
context
Application System calls
process
(user code) Exceptions
system X Interrupts
kernel
space not allowed System tasks

UNIX uses only two privilege levels


Architecture: File System Structure
 Hierarchical
/

Bin dev etc home lib mnt proc tmp usr var

passwd group bin man sbin


Typical UNIX directory
structure
Fedora Linux Directories
[root@unix /]# ls -l
total 237
drwxr-xr-x 2 root root 4096 Sep 20 17:19 bin
drwxr-xr-x 4 root root 1024 Sep 20 16:04 boot
drwxr-xr-x 23 root root 155648 Sep 20 16:13 dev
drwxr-xr-x 41 root root 4096 Sep 20 17:19 etc
drwxr-xr-x 2 root root 4096 Mar 12 2004 home
drwxr-xr-x 2 root root 4096 Mar 12 2004 initrd
drwxr-xr-x 9 root root 4096 Sep 20 17:19 lib
drwx------ 2 root root 16384 Sep 20 19:00 lost+found
drwxr-xr-x 2 root root 4096 Apr 14 20:39 misc
drwxr-xr-x 5 root root 4096 Sep 20 16:13 mnt
drwxr-xr-x 2 root root 4096 Mar 12 2004 opt
dr-xr-xr-x 50 root root 0 Sep 20 19:12 proc
drwxr-x--- 2 root root 4096 Sep 20 17:06 root
drwxr-xr-x 2 root root 12288 Sep 20 17:19 sbin
drwxr-xr-x 2 root root 4096 Mar 12 2004 selinux
drwxr-xr-x 8 root root 0 Sep 20 19:12 sys
drwxrwxrwt 2 root root 4096 Sep 20 17:28 tmp
drwxr-xr-x 14 root root 4096 Sep 20 16:03 usr
drwxr-xr-x 18 root root 4096 Sep 20 16:10 var
[root@unix /]#
 /bin
Directory Structure
 The bin directory is where all the executables binaries were kept in early Unix.Over time, as more and more
executables were added to Unix, it became quite unmanageable to keep all the executables in one place
and the bin directory split into multiple parts(/bin/sbin, /usr/bin)
 /dev
 Device drivers (screen, keyboard, harddisks etc.)
 /etc
 Unix designates the etc directory as the storage place for all the adminstrative files and information.
 /lib
 If programs want to include certain features,they can reference just the shared copy of that utility in the Unix
library rather than having a new unique copy.
 /lost+found
 When files are recovered after any sort of problem or failure,they are placed in the lost + found directory, if
the kernel cannot ascertain the proper location in the system.
 /mnt
 The mnt directory is an empty directory reserved for mounting removable filesystems like hard
disks,removable cartridge drives, and so on.
 /tmp
 The tmp directory contains temporary files created by Unix system programs. You can remove any
temporary file that does not belong to a running program.
 /usr
 The usr directory consists of several subdirectories that contain additional Unix commands and data files.
 /home
 Default location of user home directories.
 /var
 Logfiles, spools (mailqueue)
/etc: System Configuration

 /etc/passwd, /etc/shadow
 users, their permissions and parameters
 /etc/inittab
 what processes/deamons to start automatically on
system start-up
 ???
Environment Variables
[root@unix /]# env
HOSTNAME=unix.mii.lu.lv
TERM=vt100
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=::ffff:81.198.226.108 1289 22
SSH_TTY=/dev/pts/3
USER=root
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:
USERNAME=root
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
INPUTRC=/etc/inputrc
PWD=/
LANG=en_US.UTF-8
SHLVL=1
HOME=/root
BASH_ENV=/root/.bashrc
LOGNAME=root
SSH_CONNECTION=::ffff:81.198.226.108 1289 ::ffff:159.148.108.245 22
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env
OLDPWD=/sys
[root@unix /]#
Different Shells
 Bourne
 C Shell
 Korn Shell
 BASH Last login: Tue Sep 21 07:58:17 2004 from 81.198.226.108
[root@unix root]#
[root@unix root]# ps
PID TTY TIME CMD
20879 pts/7 00:00:00 bash
20905 pts/7 00:00:00 ps
[root@unix root]#
[root@unix root]# ls -l
total 64
-rw-r--r-- 1 root root 1204 Sep 20 16:11 anaconda-ks.cfg
-rw-r--r-- 1 root root 49872 Sep 20 16:11 install.log
-rw-r--r-- 1 root root 2306 Sep 20 16:11 install.log.syslog
[root@unix root]#
[root@unix root]# pwd
/root
[root@unix root]#
Users
[root@unix etc]# more passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin

 User permissions lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin


sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

 Password
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/etc/news:
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

 settings
dima:x:500:500::/home/dima:/bin/bash
[root@unix etc]#

[root@unix etc]# more shadow

 shell root:$1$Bev12JLP$T5GdFIiCIK67bwRSVGaMr.:12681:0:99999:7:::
bin:*:12681:0:99999:7:::
daemon:*:12681:0:99999:7:::

home
adm:*:12681:0:99999:7:::
 lp:*:12681:0:99999:7:::
sync:*:12681:0:99999:7:::
shutdown:*:12681:0:99999:7:::

 .mailrc etc. halt:*:12681:0:99999:7:::


mail:*:12681:0:99999:7:::
news:*:12681:0:99999:7:::
uucp:*:12681:0:99999:7:::
dima:$1$ipWEQ8AL$C3b3S2.R5gcMgGUNaAaLT.:12683:0:99999:7:::
[root@unix etc]#
[root@unix etc]# ls -l passwd shadow
-rw-r--r-- 1 root root 1163 Sep 20 16:11 passwd
-r-------- 1 root root 740 Sep 20 16:11 shadow
[root@unix etc]#
System Lifecycle: Ups &
Downs

Power Power
on off
Boot- Kernel OS RUN! Shut
loader Init Init down

Das könnte Ihnen auch gefallen