A Multiuse System:
UNIX is a multiprogramming system, it permits multiple programs to run and compete for the attention of the CPU. This can happen in two ways:
Multiple users can run separate jobs.
A single user can also run multiple jobs.
The windows operating system is a single user system where the CPU, memory and hard disk are all dedicated to a single user. Whereas in UNIX, the resources are shared between all the users. So, UNIX is a multiuser system.
In multiuser system, the computer breaks up a unit of time into several segments and each user is allotted a segment. So at any point in time, the machine will be doing the job of a single user. The moment the allotted time expires, the previous job, which was kept in pending or the job which is the queue is taken up for the execution. This process goes on until the clock has turned full-circle and the first user’s job is taken up once again.
A Multitasking System
As we know, a single user can also run multiple jobs continuously. As a user we can edit a file, print another file, send the mail and browse at one point of a time without leaving any of the application. The kernel is designed in such way that, it handles a user’s multiple needs.
In multitasking system, a user can see only one job running in the foreground and the rest of the jobs will be running in the background. We can switch between the foreground and background jobs, suspend them or even terminate them. So UNIX is a multitasking system.
UNIX Toolkit
As we know, in UNIX, the kernel is the one which looks after everything. But the kernel by itself doesn’t do all that can benefit the user.
In order to exploit the power of UNIX, we need to use some host of applications such as general purpose tools, text manipulation tools (filters), compilers, networking tools, disk fragmentation tools and system administration tools which comes with every UNIX system. So, UNIX provides a toolkit for the user benefit.
Pattern Matching
As we know ls is the command which is used to list the files available in the directory.
Example: $ ls
readme
chap01
chap02
chap03
helpdir
Suppose if we want to list the files which stars with the filename chap then by using only ls we can’t achieve that. So UNIX provides us options of using a special character know as a meta character.
Example: ls chap*
chap01
chap02
chap03
The * is a special character used by the system to indicate that it can match a number of filenames.
UNIX also supports regular expressions, which are framed with the characters from the meta characters set.
So, UNIX supports pattern matching concept also.
Programming Facility
The UNIX shell is also a programming language; it was designed for a programmer. UNIX shell contains all the features, like control structure, loops and variables, which makes UNIX as a powerful programming language. In case of windows, if I have to execute C/C++ or java programs we need to install additional software’s whereas in UNIX it is not necessary to do so, as they come with UNIX operating system.
Documentation
To know about UNIX in detail there exist many online help facilities like man command. It is the most important reference for commands and their configuration files.
Apart from the online documentation, through internet also we can download information regarding UNIX. There are several newsgroups on UNIX, where you can put your queries and get the information regarding that. The FAQ (Frequently Asked Questions) is a document that addresses common problems.
Architecture of UNIX operating system
The architecture of UNIX includes two main agencies, kernel and shell; these two handle all the work of the system by themselves. The kernel interacts with machine hardware and the shell with the user.
Kernel:-
Kernel is the core (heart or central part) of the operating system; it is a collection of routines written in C language.
Kernel will be loaded into memory when the system is booted and communicates directly with the hardware.
When the user application wants to access the hardware (hard disk or terminal), they take the help of the kernel, which performs the job on the user behalf.
User applications access the kernel through set of functions called system calls (System call is a request made by any application program to the kernel for performing specific task).
Apart from providing the support to user application, the kernel also manages the system’s memory, schedules processes, and decides their priority and many more.
Shell:-
In UNIX user always interact with kernel through commands. But computer does not have inherent capability of translating those commands into action. So, it requires a command interpreter, i.e., nothing but the shell. Shell is the interface between the user and the kernel.
In a System, there will be only one kernel running on the system, but there can be many shells running, according to user choice.
When a user enters a command, the shell thoroughly examines the keyboard input for special characters. If it finds any, it rebuilds a simplified command line and finally communicates with the kernel to make sure that command is executed.
Example: – $ echo
hello hi
hello hi
Internal and External Commands
Some commands are implemented as part of the shell itself rather than separate executable files. Such commands that are built-in are called internal commands. If a command exists both as an internal command of the shell as well as an external one (in /bin or /usr/bin), the shell will accord top priority to its own internal command with the same name. Some built-in commands are echo, pwd, etc.The File and Process. A file is an array of bytes that stores information. It is also related to another file in the sense that both belong to a single hierarchical directory structure.
A process is the second abstraction UNIX provides. It can be treated as a time image of an executable file. Like files, processes also belong to a hierarchical structure. We will be discussing the processes in detain in a subsequent chapter.
Locating Files
All UNIX commands are single words like ls, cd, cat, etc. These names are in lowercase. These commands are essentially files containing programs, mainly written in C. Files are stored in directories, and so are the binaries associated with these commands. We can find the location of an executable program using type command:
$ type ls
ls is /bin/ls
This means that when you execute ls command, the shell locates this file in /bin directory and makes arrangements to execute it.
The Path
The sequence of directories that the shell searches to look for a command is specified in its own PATH variable. These directories are colon separated. When you issue a command, the shell searches this list in the sequence specified to locate and execute it.
Internal and External Commands
Some commands are implemented as part of the shell itself rather than separate executable files. Such commands that are built-in are called internal commands. If a command exists both as an internal command of the shell as well as an external one (in /bin or /usr/bin), the shell will accord top priority to its own internal command with the same name. Some built-in commands are echo, pwd, etc.
Command Structure
UNIX commands take the following general form:
verb [options] [arguments]
where verb is the command name that can take a set of optional options and one or more optional arguments.
Commands, options and arguments have to be separated by spaces or tabs to enable the shell to interpret them as words. A contiguous string of spaces and tabs together is called a whitespace. The shell compresses multiple occurrences of whitespace into a single whitespace.
Options
An option is preceded by a minus sign (-) to distinguish it from filenames.
Example: $ ls –l
There must not be any whitespaces between – and l. Options are also arguments, but given a special name because they are predetermined. Options can be normally compined with only one – sign. i.e., instead of using
$ ls –l –a –t
we can as well use,
$ ls –lat
Because UNIX was developed by people who had their own ideas as to what options should look like, there will be variations in the options. Some commands use + as an option prefix instead of -.
Filename Arguments
Many UNIX commands use a filename as argument so that the command can take input from the file. If a command uses a filename as argument, it will usually be the last argument, after all options.
Example: cp file1 file2 file3 dest_dir
rm file1 file2 file3
The command with its options and argumens is known as the command line, which is considered as complete after [Enter] key is pressed, so that the entire line is fed to the shell as its input for interpretation and execution.
Exceptions
Some commands in UNIX like pwd do not take any options and arguments. Some commands like who may or may not be specified with arguments. The ls command can run without arguments (ls), with only options (ls –l), with only filenames (ls f1 f2), or using a combination of both (ls –l f1 f2). Some commands compulsorily take options (cut). Some commands like grep, sed can take an expression as an argument, or a set of instructions as argument.
Flexibility of Command Usage
UNIX provides flexibility in using the commands. The following discussion looks at how permissive the shell can be to the command usage.
Combining Commands
Instead of executing commands on separate lines, where each command is processed and executed before the next could be entered, UNIX allows you to specify more than one command in the single command line. Each command has to be separated from the other by a ; (semicolon).
wc sample.txt ; ls –l sample.txt
We can even group several commands together so that their combined output is redirected to a file.
(wc sample.txt ; ls –l sample.txt) > newfile
When a command line contains a semicolon, the shell understands that the command on each side of it needs to be processed separately. Here ; is known as a meta character.
Note: When a command overflows into the next line or needs to be split into multiple lines, just press enter, so that the secondary prompt (normally >) is displayed and you can enter the remaining part of the command on the next line.
1.3 The File System.
Introduction
In this chapter we will look at the file system of UNIX. We also look at types of files their significance. We then look at two ways of specifying a file viz., with absolute pathnames and relative pathnames. A discussion on commands used with directory files viz., cd, pwd, mkdir, rmdir and ls will be made. Finally we look at some of the important directories contained under UNIX file system.
Objectives
Types of files
UNIX Filenames
Directories and Files
Absolute and Relative Pathnames
pwd – print working directory
cd – change directory
mkdir – make a directory
rmdir – remove directory
The PATH environmental variable