Unix basics

What is UNIX?

Unix is an operating system that performs the following tasks:-

  • it allocates computer resources and schedules tasks (cpu, system memory, disk and tape storage, printers etc)
  • it provides an interface to the user (gives user a way to access computer resources)
  • keeps track of file names and where each file is located on the disk
  • it monitors every keystroke on each of the terminals
  • other functions include fulfilling requests made by users - running accounting programs that keep track of resource use
  • an operating system schedules tasks so that the cpu is working on only one task at a given moment, although the computer may appear to be running many programs at the same time.


History of the Unix Operating System

Unix was developed at the AT&T Bell laboratories in New Jersey by Ken Thompson in 1969. Computers were still running only single jobs in a batch mode. Input was in the form of punch cards and output was printed - disadvantages of this system are:-

  • it served only one user at a time so they were not utilizing the power and speed of the computers
  • it isolated programmers from each other
  • it was difficult to share data and programs
  • it did not promote cooperation among people working on the same project

The UNIX time-sharing system provided three major improvements over the single-user batch system:

  • it allowed more than one person to use the system at the same time (multi-user)
  • it allowed the person to communicate directly with the computer via a terminal (interactive), and
  • it made it easy for people to share data and programs

This was not the first interactive, multiuser operating system. There was Multics (Multiplexed Information and Computing Service) and the CTSS (Compatible Time Sharing System) and the Cambridge Multiple Access System were being used for several years. Multics computer systems did not talk to each other, and their operating systems performed limited tasks and only on machines for which they were written. Bell labs tried this system but was not as powerful as the developers wanted and so they continued to improve this system. UNIX designers took advantage of the work these designers had done by incorporating the most desirable aspects of each of the above mentioned systems.

Unix was developed by researchers who needed a system that would allow a group of people working on the same project to share some data and programs while keeping some data private. In 1975 Bell Labs offered it to educational institutions at a minimal cost. The schools used it in their computer science programs to ensure that the students became familiar with the program. The UNIX system was such an advanced system that the students became accustomed to this sophisticated programming system and so when they left and worked in companies they introduced the UNIX system to industry.

Not only did they introduce students to the UNIX system, but the Computer Science Research Group at University of California at Berkeley made significant changes and additions to it. So many changes were made that one of the two most popular versions of the system is called the Berkeley Software Distribution (BSD) of the UNIX system. The other major version is UNIX system V, which is a descendant from the AT&T versions. When these students graduated and started working many businesses now became aware of the UNIX system and now the opportunity arose to write programs to run on UNIX for commercial use. The things that appealed to business is its timesharing and multitasking capabilities along with the fact that it was able to work on different machines and its email capability.

Unix was popular with manufacturers because of two reasons:

  1. Advances in hardware technology have created a need for an operating system that can take advantage of available hardware power which UNIX satisfies, and
  2. Hardware manufacturers need a generic system that they can easily adapt to their machines since the cost of hardware is continually dropping.

UNIX was written almost entirely in a machine-oriented language and so it can be easily adapted to different machines. Being able to share the computer's power among many users and giving users the ability to share data and programs are central features of the system. Finally, UNIX provides an ideal software development environment.

UNIX is widely accepted as it is available on many machines including micro, mini, super computers and main frames. Even non- UNIX systems (MS-DOS and Windows NT) have adopted some of the traits of the UNIX system. UNIX is very important to the computer industry and so the need was there to standardize the program.

UNIX is an operating system that can run on many different machines and so it is referred to as being portable. Most of UNIX is written in C programming language, and C is portable because it is written in a higher level machine-independent language.

Ken Thompson originally wrote UNIX in assembler language which is a machine dependent language that works on only one machine. To make it portable, Thompson developed the B programming language (machine independent language), Dennis Ritchie, developed the C programming language by modifying the B and with Thompson, rewrote the UNIX system in C. Now the Operating System could run more easily on other machines.



The UNIX System

UNIX like other operating systems is a control program for computers, however, UNIX has a family of utility programs and a set of tools that allows users to connect and use these utilities to build systems and applications. A UNIX system can support from one to over one hundred users each concurrently running a different set of instructions. It also allows more than one user to access the same document by compartmentalizing the document so that the changes of one user does not override the changes of another; (Multi-user) each user can run more than one job at a time for example you can print a file while working on a different file; (Multi-tasking) and it can be run on many different machines with a minimum of code changes, also newer versions of the software are backwards compatible (portable). Some dates to remember:-

  • 1969 - developed by Ken Thompson
  • 1970 - written in the B language
  • 1973 - rewritten in C language - Dennis Ritchie


The UNIX programs

UNIX has many programs and these programs can be divided into two categories. Integral utilities - these are absolutely necessary for the operation of the computer, eg., command interpreter and Tools - these are necessary for the operation of UNIX while providing the users with additional capabilities for example editing a file (vi) or sending email.



The UNIX system kernel

The kernel is the heart of the UNIX OS. It controls the computer's resources and schedules user jobs so that each one gets its fair share of the resources. Programs interact with the kernel through special functions called system calls. A programmer can use a system call to interact with many different kinds of devices. When a program issues a request, the kernel interprets the context and passes the request along to the appropriate device. If you ask the computer to list all the files in a directory (ls), the kernel tells the computer to read all the files in that directory from the disk and display them on the screen.



Utilities

There are several hundred utility programs, often referred to as commands. These utilities perform functions that are used universally such as allowing users to create, display, print, copy, search, sort and delete files.



The Shell

The shell is a command interpreter that acts as an interface between users and the operating system. When you enter a command the shell interprets the command and calls the program you want. In addition to interpreting commands, the shell can be used as a high-level programming language. There are three popular shells in use today (see table below), we will be using the Korn shell. The Bash shell is relatively new and is more popular with the LINUX systems.

Shell Name

Command

the Bourne Shell

sh

the C Shell and

csh

the Korn Shell

ksh

Know your shell - Phobos - AIX RISC 6000 is running Korn Shell and Zenit is a Linux box running the bash shell.



UNIX File Concept

When using a computer you will perform file-related operations like creating, reading, writing/modifying or executing files. You therefore need to understand what a file is in UNIX and how files are organized and managed, how they are represented inside the operating system and how they are stored on the disk. In UNIX, a file is a sequence of bytes. So everything, including a network interface card, a disk drive, a keyboard, a printer, a text file or a directory is treated as a file. As a result, all input and output devices are treated as files in UNIX.

Text files- are used to store information and data on a secondary storage device, usually a disk. This file could contain a source program (in C, Java), an executable program (applications such as database tools, desktop publishing tools) pictures, audio, graphics etc. UNIX does not treat any file differently because every file is simply a sequence of bytes. Meaning is attached to a file's contents by the application that processes the file eg., C program file is read by a C compiler while an HTML file by the Web Browser and a video player eg RealPlayer, and so extensions are meaningless to UNIX. Although the operating system does not recognize filename extensions people like to use some standard extensions to make recognizing their file contents easier. Some popular extensions are:-

Extension

Contents of File

.bmp

Bit-mapped picture file

.c

C source code

.gif

Graphics/picture file

.html

File for Web page

.jpg

Joint Photographic Experts Group

.o

Object code

.ps

PostScript code

.Z

Compressed

UNIX file names can have as many as 14 letters in System V and 255 letters in BSD. You can use almost any character, however, to avoid confusion choose characters from the following:-

Uppercase (A-Z)
Lowercase (a-z)
Numbers (0-9)
Underscore ( _ )
Period (.)
Comma (,)



Directory Structure

The UNIX system is structured hierarchically (upside down tree-like). The file system structure starts with one main directory, called the root directory. You can have any number of files and subdirectories under it organized in any way. This structure leads to a parent-child relationship between a directory and its sub-directories. The root directory is at the top of the file system and is denoted as a (/). Starting with the root directory it grows downward connected by paths from the root. At the end of each path is an ordinary file or a directory file. Ordinary files (files) are at the end of paths and cannot support other paths while directory files (directories) are the points that other paths can branch from. Directories directly connected by a path ar called parents (closer to the root) and children (farther from the root).

When you log on, you are in your home directory. You can specify your home directory by using the (~) character. The directory you are in at any particular time is your current directory, or present working directory. Your present working directory is denoted (.) While the parent of the present working directory is denoted (..)

Pathnames: Absolute and Relative

A file or directory in a hierarchal file system is specified by a pathname. A pathname can be specified in one of three ways:-

  • starting with the root directory - an absolute pathname
  • starting with the present working directory - relative pathname
  • starting with the user's home directory - relative pathname


Additional Features of UNIX

Early versions of Berkeley UNIX added a full screen tex t editor (vi), a new user interface (the C shell), and virtual memory management, which enabled the UNIX system to support large applications. A networking subsystem for the support of a wide range of networking protocols was also added and this allowed users to log in on one machine and easily copy files to remote machines, run commands on remote machines and log in on remote machines.

Screen-Oriented Editor

The vi editor is an advance over its predecessor, ed, because ed displayed a line at a time, while vi displays a screenful of text.

Limitations of the UNIX system

The most commonly heard complaints about the UNIX system is that it has an unfriendly, terse, treacherous, unforgiving, inconsistent and non-mnemonic user interface. The designers of the UNIX system intended it to be used by highly skilled programmers for whom ease of use is much less important than power and flexibility. As UNIX became more popular, with a wider range of users, and new versions have made it easier to use, they have not changed the basic nature of the user interface. The shells have stayed basically the same for a good reason - many of the features that make them difficult to learn are the same ones that make them so useful for experienced users.

It is called unfriendly and terse because it follows the philosophy that "no news is good news". Some editors (ed) does not prompt you for input or commands e.g cp does not confirm that the copy was successful. A typing mistake on a command line can easily destroy important files and it is possible to log off the system inadvertently.

In summary, although UNIX has some short comings, most of them can be rectified using the tools that the UNIX system provides.



Do You Remember?

What is UNIX?
Where was UNI|X developed and by whom?
Was UNIX the first interactive, multiuser OS? If no, give an example of one of these systems.
What is another name for a utility programme?
Explain multi-user, multi-tasking and portable?
What is the kernel?
What is the shell?
What are the three popular shells today?
Which shell is popular with the LINUX system?
What is the difference between an absolute and a relative path?
What is the name of the main directory in UNIX?
What would you type to get to the parent directory, current directory and home?
What is the difference between the ed and the vi editors?
Give one of the limitations of the UNIX system?