Operating System and Shell.


  1. The Operating System.

    1. The Operating system (OS) coordinates the interaction of hardware and software. It does this by providing a system that is layered.

    2. Architecture of UNIX Systems

      Application Programs

      Commands, Compilers, Installed Software
      User written software.


      System Level Services

      Interacts with kernel via system calls
      Shell, Networks, Daemons etc.


      Kernel

      Written 90% in C
      Memory Resident
      Provides common services to programs,
      insulates them from hardware dependencies,
      allowing greater portability of programs.


      HARDWARE

      Provides the basic services.

    3. Some of the main services provided by the OS are:
      1. Device control.
        One of the elegant features of UNIX is that all devices are handled as files.
      2. Memory Management.
        This is the mapping of memory to multiple users. One of the most popular is virtual memory with demand paging.
      3. Process scheduling.
        This allows several users concurrent, but not simultaneous use of the processor. Some systems have extended this model to allow for multiple processor use. This is also called time-sharing or multiprogramming.

  2. User Interfaces
    There are two major categories of user interface: Command Line Interface (CLI) and Graphical User Interface (GUI).
    1. Command Line Interface (CLI)
      1. Allows very fine-grained control by the user.
      2. Provides for automation of common sequences of commands.
      3. Requires a longer and steeper learning curve than a GUI.
    2. Graphical User Interface (GUI)
      1. Easier to learn and easier to use for unfamiliar tasks.
      2. Less capabilities and control than CLI.
      3. Less automation capabilites.
    3. UNIX User Interfaces
      1. UNIX is primarily a CLI operating system.
      2. GUI provided by X windows system ( KDE and Gnome).
  3. The Shell
    The shell is responsible for:

    1. Program execution.
      When you give a command to the Shell, it will fork a process to execute the command. While the child process is executing the command, the parent will go to sleep. Sleeping means that the process will not use any CPU time. It remains inactive until it is awakened. When the child process has finished executing the command, it dies. The parent process, which is running the Shell, wakes up and prompts you for another command.
    2. Variable and File name substitution.
    3. I/O redirection.
    4. Process pipeline
      This is a multi-process system on UNIX, but a simple file technique on MSDOS.
    5. Environment Control.
    6. Interpreted command language.
      Allows the system to be programmed and tailored to the user. Current popular shells are:
      1. The Bourne shell - also called the standard shell.
      2. The C shell - developed as part of the Berkeley UNIX. Has a C like syntax. It allows for command line editing.
      3. The Korn shell - A refinement of the Bourne shell. It incorporates new features such as command line editing and arrays..
      4. The BASH (Bourne Again SHell) shell - A public domain shell that allows command line editing.

  4. Commands.


    1. The shell(CLI) takes commands. The general format of a command is;
      command [options] [arguments]

    2. Commands are entered in lower case. UNIX is case sensitive. MSDOS, VMS are case insensitive. Options modify the way commands work. Options are usually single letters prefixed with a minus sign (-). If arguments to the option are required they are set off by any number of spaces or tabs.

    3. Multiple options in one command can either be set off individually or combined after a single minus sign. For example:
      ls -l -a
      ls -al

    4. Spaces between command names, options and filenames are important. For example:
      ls -al is not the same as ls-al.

    5. --options.
      Some commands (frequently from the GNU project) offer alternative for the same options. For example -a can also be expressed as --all.
      ls -l --all
      These double dash full word options may be intermixed with the single leerier options, but cannot be combined like single letter options.

    6. Standard input and output
      Most commands read from standard input and write to standard output. This can be changed through redirection or piping.

      1. Output redirection is accomplished with the > symbol. For example ls >out will write the output to the file called out instead of the screen.
      2. If the file already exists and you wish to add information to it, use the >> notation. This will append to an existing file or create a new file. ls >>out
      3. To redirect input from a file instead of the terminal use <.
        mail user <note
      4. Text can be included directly in a script or command stream by using the "here" document facility <<.
        cat >new <<EDATA
        line 1
        line 2
        line 3
        EDATA
        

        In this case the lines till the EDATA are placed in the file called new.
      5. Commands can be linked together via the pipe, |. The output of one command is written to the input of the next command.

        ls | wc

    7. Examples of common commands.

      1. List who is on the system:
        $ who
        kochis   pts/0    Aug 27 06:27
        


      2. List the current working directory.
        $ pwd
        /home/kochis
        


      3. List the contents of the current working directory.
        $ ls
        Desktop  homework  mail
        


      4. A long list of the directory contents.
        $  ls -al
        total 68
        drwxr-xr-x    5 kochis   kochis       4096 Aug 23 06:14 .
        drwxr-xr-x    7 root     root         4096 Aug 22 10:19 ..
        -rw-rw-r--    1 kochis   kochis          0 Aug 23 03:43 .addressbook
        -rw-------    1 kochis   kochis       2285 Aug 23 03:43 .addressbook.lu
        -rw-r--r--    1 kochis   kochis         24 Aug 22 09:52 .bash_logout
        -rw-r--r--    1 kochis   kochis        224 Aug 22 09:52 .bash_profile
        -rw-r--r--    1 kochis   kochis        124 Aug 22 09:52 .bashrc
        drwxr-xr-x    3 kochis   kochis       4096 Aug 22 09:52 Desktop
        -rw-r--r--    1 kochis   kochis        747 Aug 22 09:52 .emacs
        drwxrwxr-x    2 kochis   kochis       4096 Aug 23 03:41 homework
        drwx------    2 kochis   kochis       4096 Aug 23 03:49 mail
        -rw-------    1 kochis   kochis      14532 Aug 23 03:43 .pinerc
        -rw-rw-r--    1 kochis   kochis         11 Aug 23 04:15 .profile
        -rw-rw-r--    1 kochis   kochis         88 Aug 23 06:14 .project
        -rw-r--r--    1 kochis   kochis       3728 Aug 22 09:52 .screenrc
        


      5. Count the lines, words and characters in a file.
        $  wc weinl1.txt
         81     215    1644 weinl1.txt
        


      6. List this month's calendar:
        $ cal
             August 2001
        Su Mo Tu We Th Fr Sa 
                  1  2  3  4
         5  6  7  8  9 10 11
        12 13 14 15 16 17 18
        19 20 21 22 23 24 25
        26 27 28 29 30 31
        


      7. Print my environment.
        $ env
        PWD=/home/kochis
        HOSTNAME=CodeRed
        QTDIR=/usr/lib/qt-2.3.0
        LESSOPEN=|/usr/bin/lesspipe.sh %s
        KDEDIR=/usr
        USER=kochis
        MACHTYPE=i386-redhat-linux-gnu
        MAIL=/var/spool/mail/kochis
        INPUTRC=/etc/inputrc
        BASH_ENV=/home/kochis/.bashrc
        LANG=en_US
        LOGNAME=kochis
        SHLVL=1
        SHELL=/bin/bash
        HOSTTYPE=i386
        OSTYPE=linux-gnu
        HISTSIZE=1000
        HOME=/home/kochis
        TERM=vt100
        SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
        PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/kochis/bin
        


      8. Sending mail without a file.
        $ mail -s "Kochis, Allan - 1" kochis
        Hi, I am Allan. 
        An interesting fact is that I teach this class!
        Ctrld 
        


      9. Sending a file to mail.
        env >junk
        $ mail -s "File test " kochis <junk
        

    © Allan Kochis Last revision 8/28/2005