UNIX – Une Introduction

Alain NINANE – RSSI UCL - A Definition (I) l Unix is a (family of) ... like ... l MS-DOS (Microsoft) l VMS (DEC) l VM/CMS, VM/SP (IBM Mainframe) l Windows (Workgroups, 95, 98) l Mac OS (..., 8, 9) l Windows NT, XP, 2000, Vista, Seven, Eight.... l Mac OS X (Leopard, Snow Leopard, Tiger, Lion, Mountain Lion,...) l (, Suse, Mandrake, Debian, Ubuntu, ...) l Solaris (SUN) l Google (ANDROID) l Apple (IOS) l ....

28 Jan 2014 Introduction 2 BIN - 2014 2/40 UNIX - A Definition (II) l UNIX is an operating system l Multi user l Multi task l Multi sessions l Fair ressources sharing l Hierarchical system l Simple processes communications

28 Jan 2014 Introduction 2 BIN - 2014 3/40 UNIX - Multi User l Simultaneous access l Authentifications mechanisms l Logins/Passwords l Secure Cards/Certificates l Protections l Files/Processes belongs to one user l Files/Processes belongs to one or groups l Enforcement of data protection by hardware l Security Model l DAC (vs MAC)

28 Jan 2014 Introduction 2 BIN - 2014 4/40 UNIX - Multi Task

l A command is the same as a user program l E.g: , , cc, myProg, myAnalysis, ... l A “running” program or command is called a process l Processes can be executed l Sequentially l Concurrently l Batch processing l Locally l In a networked environment (e.g. GRID computing) l Accept programs written in multiple languages l As long as you have a compiler ... l C, C++, Fortran, Pascal, Cobol, ...

28 Jan 2014 Introduction 2 BIN - 2014 5/40 UNIX - Multi Session (I) l Access methods to a UNIX system l Command line oriented (CLI) l Through terminals, consoles () l Terminals as windows of a GUI l Command language (scripts) l Graphical User Interfaces (GUI) l X Window System (X11, X - MIT 1984) § X Terminals over a LAN § X Clients through the Internet l News (SUN Microsystems) ~1985 § Postcript based l Aqua (Apple 1999) § Apple’s Graphical User Interface

28 Jan 2014 Introduction 2 BIN - 2014 6/40 UNIX - Multi Session (II) l Allows many users to work on the system l Locally l Through a local area network l Through the internet l Sessions l CLI l GUI

28 Jan 2014 Introduction 2 BIN - 2014 7/40 UNIX - Multi Session (III) l CLI - Network access to a UNIX system l telnet host132.bigcompany.com (tcp port 23) l Non-secure protocol l Not limited to the UNIX world (e.g. Router, printer, configuration) l rlogin host132.bigcompany.com (tcp port 513) l Non-secure protocol l Unix world l ssh host132.bigcompany.com (tcp port 22) l Secure protocol (based on ssl) l Unix world but expanding to Windows (putty, winscp...)

28 Jan 2014 Introduction 2 BIN - 2014 8/40 UNIX - Ressources Sharing (I) l UNIX shares l CPU: one second is divided in equal-sized “slices” l one slice is allocated to a process (user or system) l UNIX is a sharing system (TS suffix) l RAM: memory is divided into equal-sized “pages” l pages are allocated to a process (user or system) l DISKS: space is divided into equal-sized “blocks” l blocks are allocated to files or directories

28 Jan 2014 Introduction 2 BIN - 2014 9/40 UNIX - Ressources Sharing (II) l UNIX shares ressources fairly l CPU l Ressource allocated on a priority base l User commands and programs the same level l MEMORY l Allocated on a priority base l Unused pages saved back on disk l DISK l Allocated as far as disk space is available l Quotas can be implemented

28 Jan 2014 Introduction 2 BIN - 2014 10/40 UNIX - Hierarchical FS (I)

28 Jan 2014 Introduction 2 BIN - 2014 11/40 UNIX - Hierarchical FS (II) l Hierarchy seems natural l but VM/CMS had a flat name space (no dir !) l Filesystem Hierarchy Standard l http://www.pathname.com/fhs/ l fhs-2.3.pdf l Implementation is vendor dependent l List of UNIX (and other) file systems l http://en.wikipedia.org/wiki/Comparison_of_file_systems l local l , , ufs, hfs, advfs, , , ... l with or without journaling, versioning l case dependent, large file support (> 2GB) l networked l nfs, afs, ... 28 Jan 2014 Introduction 2 BIN - 2014 12/40 UNIX - Hierarchical FS (III) l The hierarchy holds l Directories l Files l Regular § Collection of data (bytes) § Data, program, executable § No predefined structure § Suffix is irrelevant (use magic characters) l Special § peripherals (/dev) § processes (/proc) § Named pipes, some sockets, ...

28 Jan 2014 Introduction 2 BIN - 2014 13/40 UNIX - Process Communication l Process communication made easy l Standard input and output l Simple Data redirection l myProc1 > myOutput1 l myProc2 < myOutput1 > myOutput2 l Pipes l myProc1 | myProc2 > myOutput2 l Advanced IPC l Shared memory l Synchronization l Locking l ...

28 Jan 2014 Introduction 2 BIN - 2014 14/40 UNIX - A Portable OS l Written in a high level language (C - 1973) l Widely diffused l You “just” need a C compiler on a platform to run UNIX on it. l Assembly code needed just for the bootstrap process l Runs on PCs, µP, MACs (PPC/Intel), mainframes, ... l Become a de facto IEEE standard l Portable Operating System Interface (POSIX) l IEEE 1003.x

28 Jan 2014 Introduction 2 BIN - 2014 15/40 UNIX - A philosophy l Simplicity l Small number of powerful concepts and utilities l pipes, redirections, consistent access to ressources l , , , uniq, , , , , ... l Simple communication between utilities l Scripts combining simple utilities l Regularity l very few exceptions § e.g. network socket not in the filesystem l Flexibility l easy to adapt to special needs

28 Jan 2014 Introduction 2 BIN - 2014 16/40 UNIX - A spirit :-) l Conceptors of UNIX had a sense of humour l Command “” l Copy and convert tapes from EBCDIC to ASCII l “cc” already taken as the C compiler ... -> “dd” l Command “biff” l “biff” allows you to be warned when a arrive l Biff was the name of the dog ... l Drawback l Makes the language cryptic, obscure

28 Jan 2014 Introduction 2 BIN - 2014 17/40 UNIX - Architecture (I)

28 Jan 2014 Introduction 2 BIN - 2014 18/40 UNIX - Architecture (II) l Kernel mode (space) l All protected operations l Non preemptible l Standard UNIX cannot provide Hard Real-Time capabilities l User mode (space) l All non-protected operations l Systems Calls l Allows user level process to enter the kernel l System calls are +/- standardized within the UNIX family l read(), (), (), exec(), (), ....

28 Jan 2014 Introduction 2 BIN - 2014 19/40 UNIX - A Proprietary OS l UNIX is NOT Open Software l Original source code was available since the beginning for a “small” fee l License, Royalties, ... l Source code not redistributable as is ... l UNIX ownership l l AT&T l Novell l Santa Cruz Operating System (SCO) l ... ??? ...

28 Jan 2014 Introduction 2 BIN - 2014 20/40 UNIX - A Family of OS (I) l Source Code Available l Computing “Aware” Communities l Universities, Vendors, ... l Many improvements l Berkeley: sockets, improved shell, , background processes l AT&T: l Variety of UNIX’es l BSD, Ultrix, SunOS, Digital Unix, Solaris, HP-UX, AIX, OSF, MacOSX, Linux, Next, Darwin, ...

28 Jan 2014 Introduction 2 BIN - 2014 21/40 UNIX - History (I)

28 Jan 2014 Introduction 2 BIN - 2014 22/40 UNIX - History (II)

28 Jan 2014 Introduction 2 BIN - 2014 23/40 UNIX - History (III)

28 Jan 2014 Introduction 2 BIN - 2014 24/40 UNIX - annoyances l BSD and System V flavors differs, e.g. l BSD: aux l Sys V: ps -eaf l Can be solved by compatibility environments l e.g. Solaris has a BSD environment l /usr/ucb/bin l environment: PATH=/usr/ucb/bin:$PATH

28 Jan 2014 Introduction 2 BIN - 2014 25/40 UNIX - History (IV - The Story) l The whole story l http://www.levenez.com/unix/ l unix_plotter.pdf l Just to remember l Two main flavors of UNIX l System V l Berkeley (BSD) l So ... what about Linux ?

28 Jan 2014 Introduction 2 BIN - 2014 26/40 UNIX - ... versus Linux ... l Linux is a free, open source version of the UNIX OS. l Source code written from scratch (?) with the same interface as the original UNIX l Many versions (“distro”) of Linux (Red Hat, Suse, Debian, ...) l But “one” linux kernel l “Mimic” the UNIX kernel interface l system calls l Distro’s differs from l the application/management layer l base GUI (KDE, GNOME, AfterStep, ...) l software packages (Apache, MySQL, OpenOffice, ... ) l distribution media l -desk, support, language (walloon in Red Hat :-) ) ...

28 Jan 2014 Introduction 2 BIN - 2014 27/40 Linux - Choice of a “distro” l Main usage of the system l Home usage l Server § Mid-range § High-end l Mission critical l Support l Software life cycle l Maintenance l Hardware compatibility/certification

28 Jan 2014 Introduction 2 BIN - 2014 28/40 Linux - Red Hat l Red Hat was a very popular distribution l Red Hat is now focusing on the commercial market l Last free release is Red Hat 9 l Project moved to the Fedora Core Project () l New product: (RHEL) l FC - no support - life cycle 1.5 * 6 monthes l Longer with the Fedora Legacy Project l RHEL - support - life cycle 5 x 18 monthes

28 Jan 2014 Introduction 2 BIN - 2014 29/40 Linux - Red Hat l FC - Distribution through network - free l RHEL - Distribution through commercial channels (network, CDs, ...) - paid l However - Linux is open software l RHEL source code available on the network l Fell free to recompile it l E.g. CERN Scientific l E.g. Centos l Massive deployement via kickstart

28 Jan 2014 Introduction 2 BIN - 2014 30/40 UNIX - The Computing Market l At the beginning UNIX was used within universities, research centers, ... l Mid 80’s starts to address “mini” computer and some supercomputer (Cray) l Linux is a major step toward home users l script kiddies, hackers, .... l a perfect computing laboratory l Linux is becoming more and more present ...

28 Jan 2014 Introduction 2 BIN - 2014 31/40 UNIX - vs Windows (I) l Desktop l A long debate between Win - MacOSX - Linux l French Police Dept., City of Munich, ... l Server l UNIX is taking over spec. with multi-cpus (16x) l http://www.m-tech.ab.ca/linux-biz/ l US Postal, yahoo, ebay, www.windows95.com, skynet, ... l Apple .mac accounts managed by SUN Mail servers l Embedded systems l Small and specialized distribution (knoppix, ...) l E.g. Lotto terminal, firewall appliance, kiosk, ...

28 Jan 2014 Introduction 2 BIN - 2014 32/40 UNIX - vs Windows (II)

28 Jan 2014 Introduction 2 BIN - 2014 33/40 UNIX - Summary l A very powerful OS for programmers l Provides a consistent access to ressources l Provides a well-defined interface to the kernel l Provides high level libraries l A very powerful OS for system admin. l Easy to manage l text configuration files l Command line interface l Remote access

28 Jan 2014 Introduction 2 BIN - 2014 34/40 UNIX - Documentation l man

1 - user commands 5 - file formats 2 - system calls 6 - games 3 - fct libraries 7 - misc 4 - devices/network interfaces 8 - admin commands l network l forums l books (O’Reilly)

28 Jan 2014 Introduction 2 BIN - 2014 35/40 UNIX - A First Reference

l “UNIX for Programmers and Users” l Graham Glass, King Ables l Prentice Hall - ISBN 0-13681-685-1

28 Jan 2014 Introduction 2 BIN - 2014 36/40 UNIX - Cmd Interpreters (I) l The UNIX command interpreter ... l A Shell l Used for interactive use (cli) or command scripts. l A shell is an ordinary program l Lies between the user and the UNIX OS (UI) l Executes commands on behalf of the user l Allows one to combine commands into powerful control structures

28 Jan 2014 Introduction 2 BIN - 2014 37/40 UNIX - Cmd Interpreters (II) l Bourne shell (/bin/sh) l C shell (/bin/csh) l Korn shell (/bin/ksh) l Turbo C shell (/bin/tcsh) l Z shell (/bin/zsh) l Bash (/bin/bash) l ....

28 Jan 2014 Introduction 2 BIN - 2014 38/40 UNIX - Cmd Interpreters (III)

Name Interactive Scripts

Bourne BAD OK

C Shell OK BAD

Korn Shell OK OK

Bash OK OK

28 Jan 2014 Introduction 2 BIN - 2014 39/40 UNIX - Real Life Examples

1. grep NET_DROP kernel | \ awk '{print $11}' | sort –n | uniq -c

2. tail -100000 AppleMailServer.POP.log | \ grep "with APOP" | awk '{print $7}' | sort | uniq

3. /afs ls --color=none | awk -F. '{print $NF}' | sort | uniq -c | sort -n

28 Jan 2014 Introduction 2 BIN - 2014 40/40