Вы находитесь на странице: 1из 39

Case Study | 1

UNIT 8: Case Study

Structure

8.0 Objective
8.1 Introduction
8.2 Linux Operating System
8.2.1 Introduction to Linux OS
8.2.2 Linux features and benefits
8.2.3 Systems characteristics and requirements with Linux
8.2.4 Getting started with Linux
8.3 Unix Operating System
8.3.1 Introduction to Unix OS
8.3.2 Unix features and benefits
8.3.3 Systems characteristics and requirements with Unix
8.3.4 Getting started with Unix
8.3.5 File in the UNIX System
8.3.6 UNIX Command Shells
8.3.7 The System Kernel
8.4 Summary
8.5 Exercise
8.6 Suggested Readings

8.0 Objective

At the end of this chapter you will know:

System requirements of Linux and features of Linux


How to start and run Linux system
System requirements of Unix and features of Unix
How to start and run Unix system
Unix command shells
File in the Unix system
The system kernel in Unix
2 | Operating System

8.1 Introduction

The Linux open source operating system, or Linux OS, is a freely distributable, cross-
platform operating system based on Unix that can be installed on PCs, laptops, netbooks, mobile and
tablet devices, video game consoles, servers, supercomputers and more.The Linux OS is frequently
packaged as a Linux distribution for both desktop and server use, and includes the Linux kernel (the
core of the operating system) as well as supporting tools and libraries. Popular Linux OS distributions
include Debian, Ubuntu, Fedora, Red Hat and openSUSE. UNIX was one of the first operating
systems to be written in a high-level programming language, namely C. This meant that it could be
installed on virtually any computer for which a C compiler existed. This natural portability combined
with its low price made it a popular choice among universities. It was inexpensive because antitrust
regulations prohibited Bell Labs from marketing it as a full-scale product.Due to its portability,
flexibility, and power, UNIX has become a leading operating system for workstations. Historically, it
has been less popular in the personal computer market.

8.2 LINUX operating system

8.2.1 Introduction to Linux OS

Linux is a version of the UNIX operating system. Nowadays it has gained a lot of popularity. Linux
almost resembles a UNIX system in appearance and working. This is so because it was designed
keeping in mind the compatibility with UNIX. Linux however, was developed much later. Its
development started in1991, when a Finnish student named Linus Torvalds inaugurated Linux,a
small yet self-contained kernel for the 80386 processor. It was the first true 32-bit processor in Intel's
range of PC-compatible CPUs.

During its early developmental stage, the source code for Linux was made available on the Internet
free of cost. Thus Linux has a history of collaboration from users from all around the world.
Previously, Linux system did not include a lot many features of UNIX. But the recent versions
include much of the functionalities of UNIX. In its primary stage, Linux development mainly
involved the core (central operating-system kernel). This is the privileged executive that handles all
system resources and directly interacts with the computer hardware. However, when we talk about a
full operating system, we need much more than this kernel. Before proceeding, the difference
between the Linux kernel and a Linux system should be stated. The Linux kernel is a completely
original piece of software built from scratch by the Linux community. The Linux system on the other
hand, is a collection of numerous components, some may be written from scratch, others may be
borrowed from various development projects, and yet others may be created in collaboration with
various teams.

The basic Linux system is a standard environment for user programming and applications. With the
growth of Linux, it has become necessary to use another layer of functionality above the Linux
system. A Linux distribution that meets this need, contains all the regularcomponents of the Linux
system and aset of administrative tools that can streamline the initial installation and the subsequent
upgrading of Linux. These administrative tools are also used to manage installation and removal of
Case Study | 3

other packages on the system. Additionally, a modern Linux distribution also possesses tools to
create and manage user accounts, administer networks, manage file systems and so on.

8.2.2 Linux features and benefits

LINUX has the following important features:

Portable: Linux is portable which means that it can work on different types of hardware in
the same way. Linux kernel and application programs supports their installation on any kind
of hardware platform.

Multi-User: Linux is a multiuser system means multiple users can access system resources
like memory/ ram/ application programs at same time.

Open Source: Linux source code is freely available and it is community based development
project. Multiple teams work in collaboration to enhance the capability of Linux operating
system and it is continuously evolving.

Multiprogramming: Linux is a multiprogramming system means multiple applications can


run at same time.

Shell: Linux provides a special interpreter program which can be used to execute commands
of the operating system. It can be used to do various types of operations, call application
programs. etc.

Hierarchical File System: Linux provides a standard file structure in which system files/
user files are arranged.

Security: Linux provides user security using authentication features like password
protection/ controlled access to specific files/ encryption of data.

We can think of Linux Kernel architecture to be divided into two levels User Space and Kernel
Space.

User Space

This is where the user applications are executed. There is also the GNU C Library (glibc).
This provides the system call interface that connects to the kernel and provides the
mechanism to transition between the user-space application and the kernel.

Kernel Space

Here, the Linux Kernel exists which can be further divided into three levels. At the top is the
system call interface, which implements the basic functions such as read and write. Below
the system call interface is the kernel code, which can be more accurately defined as the
architecture-independent kernel code. This code is common to all of the processor
architectures supported by Linux. Below this is the architecture-dependent code, which forms
4 | Operating System

what is more commonly called a BSP (Board Support Package). This code serves as the
processor and platform-specific code for the given architecture.

Figure 8.1: Architecture of Linux kernel

Properties of the Linux Kernel

The kernel is layered into a number of distinct subsystems. Linux can also be considered monolithic
because it lumps all of the basic services into the kernel. This differs from a microkernel architecture
where the kernel provides basic services such as communication, I/O, and memory and process
management, and more specific services are plugged in to the microkernel layer.

Functions of the Kernel

Now lets look at some of the functions of the Linux kernel.

System Call Interface

The SCI is a thin layer that provides the means to perform function calls from user space into
the kernel. As discussed previously, this interface can be architecture dependent, even within
the same processor family. You can find the SCI implementation in ./linux/kernel, as well as
architecture-dependent portions in ./linux/arch.
Case Study | 5

Figure 8.2: Functions of Linux kernel

Process Management

The kernel is in charge of creating and destroying processes and handling their connection to
the outside world (input and output). Communication among different processes (through
signals, pipes, or interposes communication primitives) is basic to the overall system
functionality and is also handled by the kernel. In addition, the scheduler, which controls
how processes share the CPU, is part of process management.

Memory management

Another important resource thats managed by the kernel is memory. For efficiency, given
the way that the hardware manages virtual memory, memory is managed in what are
called pages (4KB in size for most architectures). Linux includes the means to manage the
available memory, as well as the hardware mechanisms for physical and virtual mappings.

Filesystems

Linux is heavily based on the filesystem concept; almost everything in Linux can be treated
as a file. The kernel builds a structured filesystem on top of unstructured hardware, and the
resulting file abstraction is heavily used throughout the whole system. In addition, Linux
supports multiple file system types, that is, different ways of organizing data on the physical
medium. For example, disks may be formatted with the Linux standard ext3 filesystem, the
commonly used FAT filesystem or several others.

Device control

Almost every system operation eventually maps to a physical device. With the exception of
the processor, memory, and a very few other entities, any and all device control operations
6 | Operating System

are performed by code that is specific to the device being addressed. That code is called a
device driver. The kernel must have embedded in it a device driver for every peripheral
present on a system, from the hard drive to the keyboard and the tape drive.

Networking
Networking must be managed by the operating system, because most network operations are
not specific to a process: incoming packets are asynchronous events. The packets must be
collected, identified, and dispatched before a process takes care of them. The system is in
charge of delivering data packets across program and network interfaces, and it must control
the execution of programs according to their network activity. Additionally, all the routing
and address resolution issues are implemented within the kernel.

The following are the advantages of Linux:


Linux was one of the first open-source technologies, but many programmers have
contributed and added software thats completely open-source for any user. This means that
you can download the source code and change it any way you like. Some developers have
restrictions on how you can distribute the code. For instance, some developers allow you to
change the code, but you cannot distribute it for money.
One main advantage of open-source technologies such as Linux is the wide range of options
available to users and the increased security. With Linux being open-source, several
distributions are available to the end-user. Debian, Fedora, Ubuntu and Mint are just a few of
the distributions available to end users, and these distributions are completely free to
download.

Security is the other main advantage. Several whitehat hackers have contributed to the
overall security of Linux, and by making the source available to anyone, security experts can
help identify any main security flaws in the operating system. The advantage over operating
systems such as Windows is that security flaws are caught before they become an issue for
the public.
8.2.3 System characteristics and requirements with Linux

Linux can be install from CD/DVD available in the market or downloaded from the iso-image of
Linux distribution. But the mostly Linux is Installed by booting the system from the CD/DVD. These
CDs can be purchased from various Linux vendors depending upon the requirement of the user's
necessities.

Before installing Linux Server/ Desktop Operating System, you must be aware of the getting
preparation before installing it. There are many steps begins before installing any Linux distribution.
Here are some common steps written about generic installation, which is mostly common for most of
the Linux distribution.

Generic-installation

As it is earlier mentioned that Linux is a free open source software and all the included software
charges no fee except those additional software that are installed later. Linux is distributed under
Case Study | 7

GNU (General Public License) that's not allowed to sell the License for the Software. Linux has more
than three hundred distributions that are versatile from one another.

So the users have extra advantage to use their required Linux distribution along with their needed
additional paid software. Generally, Linux is installed from the CDs that is available in the market or
can be get directly from the various Linux vendors. Each vendor has one or more Linux distribution.
You can purchase it from them. Linux can also be installed by downloading Linux iso-mirror image
from Internet. Many times you can get some more additional software package along with Linux by
downloading it from their FTP site.

Here we are giving some information regarding what are the common requirement needed for
installing Linux on the 9x computer (Windows computer operating systems produced from 1995 to
2000). The common preparation and procedures are:

Planning
Gathering system hardware information
Backing up your old system (optional, but strongly recommended)
Preparing Linux partitions
Deciding on a boot loader (for dual boot systems)
Booting a Linux kernel
Installing the kernel
Choosing and installing software packages
Loading the software
Making final configuration adjustments
Rebooting into a running system.

Table 8.1 lists the minimum system requirements for Red Hat Enterprise Linux versions 4 and 5 on
both 32-bit and 64-bit platforms.

Table 8.1: Red Hat Enterprise Linux Operating System and Hardware Requirements

Criteria Requirements
Operating System Red Hat Enterprise Linux 4 or 5 with the latest patches and upgrades
CPU Type Pentium 4 or higher; 2 GHz or higher
Memory/RAM 1 GB minimum, up to the system limit
Hard Disk 4 GB minimum
Other To run the Directory Server using port numbers less than 1024, such as the
default port 389, you must setup and start the Directory Server as root, but it is
8 | Operating System

not necessary to run the Directory Server as root.

8.2.4 Getting started with Linux

In order to work on a Linux system directly, you will need to provide a user name and password. You
always need to authenticate to the system. Most PC-based Linux systems have two basic modes for a
system to run in: either quick and sober in text console mode, which looks like DOS with mouse,
multitasking and multi-user features, or in graphical mode, which looks better but eats more system
resources.

This is the default nowadays on most desktop computers. You know you will connect to the system
using graphical mode when you are first asked for your user name, and then, in a new window, to
type your password. To log in, make sure the mouse pointer is in the login window, provide your user
name and password to the system and click OK or press Enter.

It is generally considered a bad idea to connect (graphically) using the root user name, the system
administrators account, since the use of graphics includes running a lot of extra programs, in root's
case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to
connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of
the root account: only log in as root when extra privileges are required. After entering your user
name/password combination, it can take a little while before the graphical environment is started,
depending on the CPU speed of your computer, on the software you use and on your personal
settings.

To continue, you will need to open a terminal window or xterm for short (X being the name for the
underlying software supporting the graphical environment). This program can be found in the
Applications->Utilities, System Tools or Internet menu, depending on what window manager you are
using. There might be icons that you can use as a shortcut to get an xterm window as well, and
clicking the right mouse button on the desktop background will usually present you with a menu
containing a terminal window application. While browsing the menus, you will notice that a lot of
things can be done without entering commands via the keyboard.

For most users, the good old point-'n'-click method of dealing with the computer will do. But this
guide is for future network and system administrators, who will need to meddle with the heart of the
system. They need a stronger tool than a mouse to handle all the tasks they will face. This tool is the
shell, and when in graphical mode, we activate our shell by opening a terminal window. The terminal
window is your control panel for the system. Almost everything that follows is done using this simple
but powerful text tool. A terminal window should always show a command prompt when you open
one. This terminal shows a standard prompt, which displays the user's login name, and the current
working directory, represented by the twiddle (~):
Case Study | 9

Figure 8.3: Terminal Window

Another common form for a prompt is this one: [user@hostdir] In the above example, user will be
your login name, hosts the name of the machine you are working on, and dir an indication of your
current location in the file system. Later we will discuss prompts and their behavior in detail. For
now, it suffices to know that prompts can display all kinds of information, but that they are not part
of the commands you are giving to your system. To disconnect from the system in graphical mode,
you need to close all terminal windows and other applications. After that, hit the logout icon or find
Log Out in the menu. Closing everything is not really necessary, and the system can do this for you,
but session management might put all currently open applications back on your screen when you
connect again, which takes longer and is not always the desired effect. However, this behavior is
configurable. When you see the login screen again, asking to enter user name and password, logout
was successful.

Gnome or KDE?

We mentioned both the Gnome and KDE desktops already a couple of times. These are the two most
popular ways of managing your desktop, although there are many, many others. Whatever desktop
you chose to work with is fine - as long as you know how to open a terminal window. However, we
will continue to refer to both Gnome and KDE for the most popular ways of achieving certain tasks.

You know you're in text mode when the whole screen is black, showing (in most cases white)
characters. A text mode login screen typically shows some information about the machine you are
working on, the name of the machine and a prompt waiting for you to log in: RedHat Linux Release
8.0 (Psyche) blast login: _ The login is different from a graphical login, in that you have to hit the
Enter key after providing your user name, because there are no buttons on the screen that you can
click with the mouse. Then you should type your password, followed by another Enter. You won't see
any indication that you are entering something, not even an asterisk, and you won't see the cursor
move. But this is normal on Linux and is done for security reasons. When the system has accepted
you as a valid user, you may get some more information, called the message of the day, which can be
anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains
10 | Operating System

some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell,
indicated with the same prompt that you would get in graphical mode. Don't log in as root Also in
text mode: log in as root only to do setup and configuration that absolutely requires administrator
privileges, such as adding users, installing software packages, and performing network and other
system configuration. Once you are finished, immediately leave the special account and resume your
work as a non-privileged user.

Alternatively, some systems, like Ubuntu, force you to use sudo, so that you do not need direct access
to the administrative account. Logging out is done by entering the logout command, followed by
Enter. You are successfully disconnected from the system when you see the login screen again. The
power button While Linux was not meant to be shut off without application of the proper procedures
for halting the system, hitting the power button is equivalent to starting those procedures on newer
systems. However, powering off an old system without going through the halting process might cause
severe damage! If you want to be sure, always use the Shut down option when you log out from the
graphical interface, or, when on the login screen (where you have to give your user name and
password) look around for a shutdown button.

8.3 UNIX operating system

8.3.1 Introduction to Unix OS


The UNIX operating system is a set of programs that act as a link between the computer and the user.
The computer program that allocates the system resources and coordinates all the details of the
computer's internals is called the operating system or the kernel. Users communicate with the kernel
through a program known as the shell. The shell is a command line interpreter; it translates
commands entered by the user and converts them into a language that is understood by the kernel.

UNIX was originally developed in 1969 by a group of AT&T employees Ken Thompson,
Dennis Ritchie, Douglas McIlroy, and Joe Ossanna at Bell Labs.
There are various UNIX variants available in the market. Solaris UNIX, AIX, HP UNIX and
BSD are a few examples. Linux is also a flavor of UNIX which is freely available.
Several people can use a UNIX computer at the same time; hence UNIX is called a multiuser
system.
A user can also run multiple programs at the same time; hence UNIX is a multitasking
environment.

Figure 8.4showsa basic block diagram of a UNIX system


Case Study | 11

Figure 8.4: Basic block diagram of a UNIX system

The main concept that unites all the versions of UNIX are:

Kernel: The kernel is the heart of the operating system. It interacts with the hardware and
most of the tasks like memory management, task scheduling and file management.

Shell: The shell is the utility that processes your requests. When you type in a command at
your terminal, the shell interprets the command and calls the program that you want. The
shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are the
most famous shells which are available with most of the UNIX variants.

Commands and Utilities: There are various commands and utilities which you can make use
of in your day to day activities. cp, mv, cat and grep, etc. are few examples of commands and
utilities. There are over 250 standard commands plus numerous others provided through 3rd
party software. All the commands come along with various options.
12 | Operating System

Files and Directories: All the data of UNIX is organized into files. All files are then
organized into directories. These directories are further organized into a tree-like structure
called the filesystem.

8.3.2 Unix features and benefits


The following are the features of UNIX:
Portability: The system is written in high-level language making it easier to read,
understand, change and, therefore move to other machines. The code can be changed and
complied on a new machine. Customers can then choose from a wide variety of hardware
vendors without being locked in with a particular vendor.

Machine-independence: The System hides the machine architecture from the user, making it
easier to write applications that can run on micros, mins and mainframes.

Multi-Tasking: Unix is a powerful multi-tasking operating system; it means when a active


task in in process, there can be a simultaneous background process working too. Unix
handles these active and background threads efficiently and manages the system resources in
a fair-share manner.

Multi-User Operations: UNIX is a multi-user system designed to support a group of users


simultaneously. The system allows for the sharing of processing power and peripheral
resources, white at the same time providing excellent security features.

Hierarchical File System: UNIX uses a hierarchical file structure to store information. This
structure has the maximum flexibility in grouping information in a way that reflects its
natural state. It allows for easy maintenance and efficient implementation.

UNIX shell: UNIX has a simple user interface called the shell that has the power to provide
the services that the user wants. It protects the user from having to know the intricate
hardware details.

Pipes and Filters: UNIX has facilities called Pipes and Filters which permit the user to
create complex programs from simple programs.

Utilities: UNIX has over 200 utility programs for various functions. New utilities can be
built effortlessly by combining existing utilities.

The following are the advantages of UNIX:


Multi-user & Multi-tasking: Most versions of UNIX are capable of allowing multiple users
to log onto the system, and have each run multiple tasks. This is standard for most modern
OSs.

Over 30 Years Old: UNIX is over 30 years old and its popularity and use is still high. Over
these years, many variations have spawned off and many have died off, but most modern
UNIX systems can be traced back to the original versions. It has endured the test of time. For
Case Study | 13

reference, Windows at best is half as old (Windows 1.0 was released in the mid-80s, but it
was not stable or very complete until the 3.x family, which was released in the early 90s).

Large Number of Applications: There are an enormous amount of applications available for
UNIX operating systems. They range from commercial applications such as CAD, Maya,
WordPerfect, to many free applications.

Free Applications and Even a Free Operating System: Of all of the applications available
under UNIX, many of them are free. The compilers and interpreters that we use in most of
the programming courses here at UMBC can be downloaded free of charge. Most of the
development that we do in programming courses is done under the Linux OS.

Less Resource Intensive: In general, most UNIX installations tend to be much less
demanding on system resources. In many cases, the old family computer that can barely run
Windows is more than sufficient to run the latest version of Linux.

Internet Development: Much of the backbone of the Internet is run by UNIX servers. Many
of the more general web servers run UNIX with the Apache web server - another free
application

8.3.3 Systems characteristics and requirements with UNIX


We consider the case where Symantec ESM (Enterprise Security Manager) agents and manager are to
be installed on a UNIX system. The minimum system requirements for the same have been listed in
table 8.2.

Table 8.2: System requirements for ESM manager+agent and ESM agent on UNIX computers

Hardware Minimum requirement

ESM manager + agent ESM agent

Physical memory 2 GB 512 MB

Hard disk space 25 GB 450 MB

Swap space 4 GB 1 GB

CPU 2.8 GHz 1.33 GHz

Network speed 100 Mbps 10 Mbps


14 | Operating System

8.3.4 Getting started with UNIX


The system manager usually sets up a user name, which is typically your first or last name, and lets
you specify a password for security. No one can access the system through your account without your
password. Keep your password secret.

To use the operating system, your operating system must be installed and running and you must be
logged in. Logging in identifies you as a valid system user and creates a work environment that
belongs to you alone.Before logging in, obtain your username and password from the system
administrator. A username (typically your surname or initials) identifies you as an authorized user. A
password (a group of characters that is easy for you to remember but difficult for others to guess)
verifies your identity.

Think of your username and password as electronic keys that give you access to the system. When
you enter your username and password during the login process, you identify yourself as an
authorized user.Your password is an important part of system security because it prevents
unauthorized use of your data. The first step in the login process is to display the login prompt. When
your system is running and your workstation is on, a login prompt appears on your screen.

On some systems, you may have to press the Return key a few times to display the login prompt.

Your system's login prompt screen may be somewhat different. For example, in addition to the login
prompt, the screen may display the system name and the version number of the operating system.

To log in, perform the following steps:

1. Enter your username at the login prompt. If you make a mistake, use the Delete key or
Backspace key to correct it.

For example, if your username is larry, enter:

login: larry

The password prompt appears:

login: larry

Password:

2. Enter your password. For security reasons, the password does not display on the screen when
you type it.

If you think you made a mistake while typing your password, press the Return key. If your password
is incorrect, the system displays a message and prompts you to enter your username and password
again.After you enter your username and password correctly, the system displays the shell
prompt, usually a dollar sign ($) prompt or a percent sign (%) prompt. Your system's shell prompt
may be different.
Case Study | 15

When you are ready to end your work session, log out of the system. Logging out leaves the
operating system running for other users and also ensures that no one else can use your work
environment.

To log out, perform the following steps:


1. Make sure that the shell prompt is displayed.
2. Press Ctrl +D. If Ctrl +D do not work, enter the exit command.
The system displays the login prompt. On some systems, a message may also be displayed.
Entering a command is an interactive process. When you enter a command, the shell interprets that
command, and then gives an appropriate response - that is, the system either runs the program or
displays an error message.A shell reads every command you enter and directs the operating system to
do what is requested. Therefore, the shell is a command interpreter.

The shell acts as a command interpreter in the following way:

1. The shell displays a shell prompt and waits for you to enter a command.

2. You enter a command; the shell analyzes it, and locates the requested program.

3. The shell asks the system to run the program, or it returns an error message.

4. When the program completes execution, control returns to the shell, which again displays the
prompt.

Figure 8.5 shows the relationship between the user, the shell, and the operating system. The shell
interacts with both the user to interpret commands and with the operating system to request command
execution.

Figure 8.5: Shell interaction with the user and the operating system
16 | Operating System

8.3.5 File in the UNIX System


A file system is a logical collection of files on a partition or disk. A partition is a container for
information and can span an entire hard drive if desired.Your hard drive can have various partitions
which usually contain only one file system, such as one file system housing the /file system or
another containing the /home file system.

One file system per partition allows for the logical maintenance and management of differing file
systems.Everything in UNIX is considered to be a file, including physical devices such as DVD-
ROMs, USB devices, and floppy drives.UNIX uses a hierarchical file system structure, much like an
upside-down tree, with root (/) at the base of the file system and all other directories spreading from
there.

A UNIX filesystem is a collection of files and directories that has the following properties:
It has a root directory (/) that contains other files and directories.

Each file or directory is uniquely identified by its name, the directory in which it resides, and
a unique identifier, typically called an inode.

By convention, the root directory has an inode number of 2 and the lost+found directory has
an inode number of 3. Inode numbers 0 and 1 are not used. File inode numbers can be seen
by specifying the -i option to ls command.

It is self-contained. There are no dependencies between one filesystem and another.

The directories have specific purposes and generally hold the same types of information for easily
locating files. Table 8.3 shows the directories that exist on the major versions of UNIX:

Table 8.3: Directories on the major versions of UNIX

Directory Description

/ This is the root directory which should contain


only the directories needed at the top level of the
file structure
/bin This is where the executable files are located.
These files are available to all users
/dev These are device drivers

/etc Supervisor directory commands, configuration


files, disk configuration files, valid user lists,
groups, Ethernet, hosts, where to send critical
messages
Case Study | 17

/lib Contains shared library files and sometimes other


kernel-related files
/boot Contains files for booting the system
/sbin Contains binary (executable) files, usually for
system administration. For example, fdisk and
ifconfigutilities.

/var Typically contains variable-length files such as


log and print files and any other type of file that
may contain a variable amount of data

/usr Used for miscellaneous purposes, and can be


used by many users. Includes administrative
commands, shared files, library files, and others

/tmp Holds temporary files used between system boots

/tmp Holds temporary files used between system boots

/proc Contains all processes marked as a file by


process number or other information that is
dynamic to the system

/mnt Used to mount other temporary file systems, such


as CD-ROM and floppy for the CD-ROM drive
and floppy diskette drive, respectively

/home Contains the home directory for users and other


accounts
/kernel Contains kernel files
18 | Operating System

Figure 8.6 below shows a diagram of a "typical" UNIX file system.

Figure 8.6: Diagram of a "typical" UNIX file system.


The Table 8.4below shows the various commands and their description with which we can work to
complete certain task.
Table 8.4: Various commands and their description

Command & Description

cat filename: Displays a filename

cd dirname: Moves you to the identified directory

cp file1 file2: Copies one file/directory to the specified location

file filename: Identifies the file type (binary, text, etc)

find filename dir: Finds a file/directory

head filename: Shows the beginning of a file


Case Study | 19

less filename: Browses through a file from the end or the beginning

ls dirname: Shows the contents of the directory specified

mkdirdirname: Creates the specified directory

more filename: Browses through a file from the beginning to the end

mv file1 file2: Moves the location of, or renames a file/directory

pwd: Shows the current directory the user is in

rm filename: Removes a file

rmdirdirname: Removes a directory

tail filename: Shows the end of a file

touch filename: Creates a blank file or modifies an existing file or its


attributes

whereis filename: Shows the location of a file

which filename: Shows the location of a file if it is in your PATH

The df Command
The first way to manage your partition space is with the df (disk free) command. The command df -k
(disk free) displays the disk space usage in kilobytes, as given below:

$df -k

Filesystem 1K-blocks Used Available Use% Mounted on


/dev/vzfs 10485760 7836644 2649116 75% /
/devices 0 0 0 0% /devices
$
The df -k output is generally the same on all Unix systems. The Table 8.5includes the following
command and description:

Table 8.5: df command and description


20 | Operating System

Command& Description

filesystem: The physical file system name

kbytes: Total kilobytes of space available on the storage medium

used: Total kilobytes of space used (by files)

avail: Total kilobytes available for use

capacity: Percentage of total space used by files

mounted on:What the file system is mounted on

Removable file volumes:


Removable file support includes Iomega ZIP drives and JAZ drives, and CD-ROM drives. Support
for removable file devices allows portability of media between UNIX systems. It also allows this
media to be used to transfer data between systems that support the media. Removable file support
allows the server to read data from a FILE device class that is copied to removable file media through
third-party software. The media is then usable as input media on a target Storage Manager Server that
uses the REMOVABLEFILE device class for input.

Note:
Software for writing CD-ROMs may not work consistently across platforms.
Use a MAXCAPACITY value that is less than one CD-ROM's usable space to allow for a one-to-one
match between files from the FILE device class and copies that are on CD-ROM. Use the DEFINE
DEVCLASS or UPDATE DEVCLASS commands to set the MAXCAPACITY parameter of the
FILE device class to a value less than 650MB.

Example of Removable File Support


Use these steps as an example of Storage Manager REMOVABLEFILE (CD-ROM) support. This
example takes an export object and moves it from one server to another.

Server A
1. Define a device class with a device type of FILE.

2. define devclass file devtype=file directory=/home/user1

3. Export the node. This command results in a file name /home/user1/CDR03 that contains the
export data for node USER1.
Case Study | 21

4. export node user1 filedata=all devclass=file vol=cdr03

You can use software for writing CD-ROMs to create a CD with volume label CDR03 that contains a
single file that is also named CDR03.

Server B
1. Follow the manufacturer's instructions to attach the device to your server.

2. Issue this command on your system to mount the CD-ROM.

3. mount -t iso9660 /dev/cdrom /cdrom

-t iso9660:Specifies that the media has a CD file system


/dev/cdrom:Specifies the physical description of the first CD-ROM on the system
/cdrom:Specifies the mount point of the first CD-ROM drive
Note:
CD-ROM drives lock while the file system is mounted. This prevents use of the eject
button on the drive.

4. Ensure that the media is labeled. The software that you use for making a CD also labels the
CD. Before you define the drive, you must put formatted, labeled media in the drive. When
you define the drive, the server verifies that a valid file system is present.
5. Define a manual library named CDROM:
6. define library cdromlibtype=manual
7. Define the drive in the library:
8. define drive cdromcddrive
9. Define a path from the server to the drive at mount point /cdrom:
10. define path serverbcddrivesrctype=server desttype=drive
11. library=cdrom device=/cdrom
12. Define a device class with a device type of REMOVABLEFILE. The device type must be
REMOVABLEFILE.
13. define devclasscdromdevtype=removablefile library=cdrom
14. Issue the following Storage Manager command to import the node data on the CD-ROM
volume CDR03.
15. import node user1 filedata=all devclass=cdromvol=cdr03
For mounting removable file other than CD-ROM, use the following command:
mount -t ext2 /dev/hdc1 /tsmrfile
22 | Operating System

Labeling Requirements for Removable Files Devices


Storage Manager does not provide utilities to format or label media for the REMOVABLEFILE
device type. You must use another application to copy the FILE device class data from the CD-ROM
as a file that has the same name as the volume label. The software used to copy the FILE device class
data must also label the removable media. CD-ROMs must be formatted using the ISO9660
filesystem. Other removablefile volumes such as Jaz or Zip must be formatted using the EXT2
filesystem and the '-L' option on the mke2fs command must be used to specify the volume label.

The label on the media must meet the following restrictions:


No more than 11 characters

No embedded blanks or periods

File name must be the same as the volume label

8.3.6 UNIX Command Shells


The shell provides you with an interface to the UNIX system. It gathers input from you and executes
programs based on that input. When a program finishes executing, it displays that program's output.

A shell is an environment in which we can run our commands, programs, and shell scripts. There are
different flavors of shells, just as there are different flavors of operating systems. Each flavor of shell
has its own set of recognized commands and functions.

The prompt, $, which is called the command prompt, is issued by the shell. While the prompt is
displayed, you can type a command. Shell reads your input after you press Enter. It determines the
command you want executed by looking at the first word of your input. A word is an unbroken set of
characters. Spaces and tabs separate words.

Following is a simple example of the date command, which displays the current date and time
$date

Thu Jun 25 08:30:19 MST 2009

You can customize your command prompt using the environment variable PS1 explained in the
Environment tutorial.

In UNIX, there are two major types of shells


Bourne shell If you are using a Bourne-type shell, the $ character is the default prompt.

C shell If you are using a C-type shell, the % character is the default prompt.

The Bourne Shell has the following subcategories


Bourne shell (sh)

Korn shell (ksh)


Case Study | 23

Bourne Again shell (bash)

POSIX shell (sh)

The different C-type shells follow


C shell (csh)

TENEX/TOPS C shell (tcsh)

The original UNIX shell was written in the mid-1970s by Stephen R. Bourne while he was at the
AT&T Bell Labs in New Jersey. Bourne shell was the first shell to appear on UNIX systems, thus it
is referred to as "the shell". Bourne shell is usually installed as /bin/sh on most versions of UNIX.
For this reason, it is the shell of choice for writing scripts that can be used on different versions of
UNIX.

Input Handling by the Shells:


The input of a command be redirected from a file. As the greater-than character > is used for output
redirection, the less-than character < is used to redirect the input of a command.The commands that
normally take their input from the standard input can have their input redirected from a file in this
manner. For example, to count the number of lines in the file users generated above, you can execute
the command as follows

$ wc -l users

2 users

Upon execution, you will receive the following output. You can count the number of lines in the file
by redirecting the standard input of the wc command from the file users

$ wc -l < users

Note that there is a difference in the output produced by the two forms of the wc command. In the
first case, the name of the file users is listed with the line count; in the second case, it is not.In the
first case, wc knows that it is reading its input from the file users. In the second case, it only knows
that it is reading its input from standard input so it does not display file name.

Here document:

A here document is used to redirect input into an interactive shell script or program. We can run an
interactive program within a shell script without user action by supplying the required input for the
interactive program, or interactive shell script.
24 | Operating System

The general form for a here document is


command << delimiter

document

delimiter

Here the shell interprets the << operator as an instruction to read input until it finds a line containing
the specified delimiter. All the input lines up to the line containing the delimiter are then fed into the
standard input of the command. The delimiter tells the shell that the here document has completed.
Without it, the shell continues to read the input forever. The delimiter must be a single word that does
not contain spaces or tabs.

Following is the input to the command wc -l to count the total number of lines
$wc -l << EOF

This is a simple lookup program

for good (and bad) restaurants

in Cape Town.

EOF

You can use the here document to print multiple lines using your script as follows
#!/bin/sh

cat << EOF

This is a simple lookup program

for good (and bad) restaurants

in Cape Town.

EOF

Upon execution, you will receive the following result


This is a simple lookup program

for good (and bad) restaurants

in Cape Town.

The following script runs a session with the vi text editor and saves the input in the file test.txt.
Case Study | 25

#!/bin/sh

filename=test.txt

vi $filename <<EndOfCommands

This file was created automatically from

a shell script

EndOfCommands

If you run this script with vim acting as vi, then you will likely see output like the following
$ sh test.sh

Vim: Warning: Input is not from a terminal

After running the script, you should see the following added to the file test.txt
$ cat test.txt

This file was created automatically from

a shell script

Shell Programming Language


A UNIX shell is a command-line interpreter or shell that provides a traditional Unix-like command
line user interface. Users direct the operation of the computer by entering commands as text for a
command line interpreter to execute, or by creating text scripts of one or more such commands. Users
typically interact with a UNIX shell using a terminal emulator, however, direct operation via serial
hardware connections, or networking session, are common for server systems. All UNIX shells
provide filename wildcarding, piping, here documents, command substitution, variables and control
structures for condition-testing and iteration.

The most generic sense of the term shell means any program that users employ to type commands. A
shell hides the details of the underlying operating system and manages the technical details of the
operating system kernel interface, which is the lowest-level, or "inner-most" component of most
operating systems.

In Unix-like operating systems, users typically have many choices of command-line interpreters for
interactive sessions. When a user logs into the system interactively, a shell program is automatically
executed for the duration of the session. The type of shell, which may be customized for each user, is
typically stored in the user's profile, for example in the local password file or in a distributed
26 | Operating System

configuration system such as NIS or LDAP; however, the user may execute any other available shell
interactively.

The Unix shell is both an interactive command language as well as a scripting programming
language, and is used by the operating system as the facility to control (shell script) the execution of
the system. Shells created for other operating systems often provide similar functionality.

On hosts with a windowing system, like mac-OS, some users may never use the shell directly. On
UNIX systems, the shell has historically been the implementation language of system startup scripts,
including the program that starts a windowing system, configures networking, and many other
essential functions. However, some system vendors have replaced the traditional shell-based startup
system (init) with different approaches, such as systemd.

Running UNIX Shells:


Shebang - what's that about and how it relates to running a shell script?
Why in the world do we have to start our shell scripts with the #! characters - the "shebang"? That is
a good question, one that many people do not even ask, they just assume "that's the way it is".
Consider this VERY simple two-line shell script:

#! /usr/bin/env bash

echo "Hello from myscript"

Shebang is the sequence "#!" that we find at the very beginning of most shell scripts.
The shebang sequence is in reality a human readable instance of a magic number in the executable
file. The magic number - 0x23 0x21 is in fact the ASCII of #!. This magic number is detected by the
execve call that actually executes the shell script. (We can find out more about execve, which is part
of the "exec" family of functions, on the exec man page.) So the exec call receives the command line
and determines from the magic number whether the file is a script or

an executable binary.

If the magic number is '#!' then "exec" knows the file is a shell script. If the magic number is '.ELF'
then "exec" knows the file is an executable binary file. When a shell script is found, then exec will
launch the proper shell interpreter.Once "exec" knows to handle our file as a shell script, it then looks
at the command specified on the shebang line. This command is most commonly the interpreter that
we want to execute our shell script.

One caveat to this in that by using the command.

#! /usr/bin/env bash
as the first line of our shell script, we make our script more portable. Not all Linux systems have the
shell interpreters - sh, bash, csh, ksh - located in /bin. By using the /usr/bin/env command we ensure
that the proper shell interpreter executes our shell script.
Case Study | 27

We have 4 different methods for running a shell script, which we will review below. A simple script
named "myscript" will be used to demonstrate usage. It contains the following lines.

#! /usr/bin/env bash

echo "Hello from myscript"

Method 1 - Use the filename to run the shell script:


This is probably the most common, as well as the simplest and straightest forward, method to execute
shell scripts. This method requires us to have the shebang line in our script. We simply use the
absolute pathname or the relative pathname to specify the shell script to execute.

$ cd /home/pbmac/scripts

$ ./myscript

or

$ /home/pbmac/scripts/myscript

The output appears on the terminal:

Hello from myscript

Method 2 - Specify the interpreter as a way to execute the shell script:


We can also execute a shell script by specifying the interpreter on the command line.
$ bash myscript
Hello from myscript
This tells "exec" to use the bash shell to run the myscript file. For specifying the interpreter on the
command line forces Linux to use that shell to run the script, no matter what is specified on the
shebang line inside of the script. Using the wrong interpreter from the command line may cause the
script to fail, or to run in an unintended manner.

Since we are specifying which shell interpreter will be used on the command line THIS is an instance
where we do not have to include a shebang line in the file. However, it is a wise habit to include the
shebang line, including the appropriate shell interpreter in your file to avoid any confusion by
someone else who may run or make updates to your script.

Method 3 - Using ../ (dot space dot slash) to execute the shell script
This syntax is the least used syntax for running a shell script, mainly due to its somewhat odd syntax.
Using this method will execute the shell script in the current shell without forking a new shell
instance to run the script.This method (and the source command below) actually runs the shell script
in the same process id as the current command line shell. What is the advantage of this?

There are two files that control your login environment.bashrc or .bash_profile (sometimes you will
not find both of these files in your home directory - that's okay). If you edit one or both of these files,
28 | Operating System

the changes do NOT take effect until the files are executed. Now, if you simply run them as a shell
script the new shell that is created will have the new settings, but NOT your login shell. After the
changes are made we can either logout or login back in to allow the changes to take effect, or we can
use the "dot space dot slash" method to execute the altered file for the changes to take place.

For instance,
$ . ./.bashrc

or

$ . ./.bash_profile

However, we can execute any shell script in this manner,


$ . ./myscript

Hello from myscript

Method 4 - Using the source command to execute the shell script:


The last method is probably the second most used method to run a shell script. It uses the built-in
source command. This is the same as the dot (.) method explained above. For some people using the
dot space dot slash seems odd, so the alternative is this source command.

$ source ./myscript

Hello from myscript

Pipes:
You can connect two commands together so that the output from one program becomes the input of
the next program. Two or more commands connected in this way form a pipe.To make a pipe, you
need to put a vertical bar (|) on the command line between two commands.

The grep Command:


The grep command searches a file or files for lines that have a certain pattern. The syntax is
$grep pattern file(s)
The name "grep" comes from the ed (a Unix line editor) command g/re/p which means globally
search for a regular expression and print all lines containing it. A regular expression is either some
plain text (a word, for example) and/or special characters used for pattern matching.The simplest use
of grep is to look for a pattern consisting of a single word. It can be used in a pipe so that only those
lines of the input files containing a given string are sent to the standard output. If you don't give grep
a filename to read, it reads its standard input; that's the way all filter programs work

$ls -l | grep "Aug"

-rw-rw-rw- 1 john doc 11008 Aug 6 14:10 ch02


Case Study | 29

-rw-rw-rw- 1 john doc 8515 Aug 6 15:30 ch07

-rw-rw-r-- 1 john doc 2488 Aug 15 10:51 intro

-rw-rw-r-- 1 carol doc 1605 Aug 23 07:35 macros

There are various options which you can use along with the grep command description.
1. -v: Prints all lines that do not match pattern.

2. -n: Prints the matched line and its line number.

3. -l: Prints only the names of files with matching lines (letter "l")

4. -c: Prints only the count of matching lines.

5. -i: Matches either upper or lowercase.

Let us now use a regular expression that tells grep to find lines with "carol", followed by zero or
other characters abbreviated in a regular expression as".*"), then followed by "Aug".

Here, we are using the -i option to have case insensitive search:


$ls -l | grep -i "carol.*aug"

-rw-rw-r-- 1 carol doc 1605 Aug 23 07:35 macros

uname Command:
Type the following command:

$ uname a

This command works with Linux, BSD and other UNIX like operating systems. The following is a
sample output of the command.

Linux wks01 2.6.32-5-amd64 #1 SMP Tue Jun 14 09:42:28 UTC 2011 x86_64 GNU/Linux

8.3.7 The System Kernel


At the center of the UNIX system is a program called the kernel. Although you are unlikely to deal
with the kernel directly, it is absolutely crucial to the operation of the UNIX system. The kernel
provides the essential services that make up the heart of UNIX systems; it allocates memory, keeps
track of the physical location of files on the computer's hard disks, loads and executes binary
programs such as shells, and schedules the task swapping without which UNIX systems would be
incapable of doing more than one thing at a time. The kernel accomplishes all these tasks by
providing an interface between the other programs running under its control and the physical
30 | Operating System

hardware of the computer; this interface, the system call interface, effectively insulates the other
programs on the UNIX system from the complexities of the computer.

For example, when a running program needs access to a file, it cannot simply open the file; instead it
issues a system call which asks the kernel to open the file. The kernel takes over and handles the
request, then notifies the program whether the request succeeded or failed. To read data in from the
file takes another system call; the kernel determines whether or not the request is valid, and if it is,
the kernel reads the required block of data and passes it back to the program. Unlike DOS (and some
other operating systems), UNIX system programs do not have access to the physical hardware of the
computer. All they see are the kernel services, provided by the system call interface.

The system call interface is an example of an API, or application programming interface. An API is a
set of system calls with strictly defined parameters, which allow an application (or other program) to
request access to a service; it literally acts as an interface. (For example, a large database system
might provide an API that allows programmers to write external programs that request services from
the database.

Process Co-ordinations and Management:


Whenever you issue a command in UNIX, it creates, or starts, a new process. When you tried out the
ls command to list the directory contents, you started a process. A process, in simple terms, is an
instance of a running program.The operating system tracks processes through a five-digit ID number
known as the pid or the process ID. Each process in the system has a unique pid.Pids eventually
repeat because all the possible numbers are used up and the next pid rolls or starts over. At any point
of time, no two processes with the same pid exist in the system because it is the pid that UNIX uses
to track each process.

Starting a Process
When you start a process (run a command), there are two ways you can run it

Foreground Processes

Background Processes

Foreground Processes
By default, every process that you start runs in the foreground. It gets its input from the keyboard and
sends its output to the screen.You can see this happen with the ls command. If you wish to list all the
files in your current directory, you can use the following command.

$ls ch*.doc
This would display all the files, the names of which start with ch and end with .doc.
ch01-1.doc ch010.doc ch02.doc ch03-2.doc
ch04-1.doc ch040.doc ch05.doc ch06-2.doc
ch01-2.doc ch02-1.doc
Case Study | 31

The process runs in the foreground, the output is directed to my screen, and if the ls command wants
any input (which it does not), it waits for it from the keyboard.

While a program is running in the foreground and is time-consuming, no other commands can be run
(start any other processes) because the prompt would not be available until the program finishes
processing and comes out.

Background Processes
A background process runs without being connected to your keyboard. If the background process
requires any keyboard input, it waits. The advantage of running a process in the background is that
you can run other commands; you do not have to wait until it completes to start another!

The simplest way to start a background process is to add an ampersand (&) at the end of the
command.

$ls ch*.doc &


This displays all those files the names of which start with ch and end with .doc.
ch01-1.doc ch010.doc ch02.doc ch03-2.doc
ch04-1.doc ch040.doc ch05.doc ch06-2.doc
ch01-2.doc ch02-1.doc
Here, if the ls command wants any input (which it does not), it goes into a stop state until we move it
into the foreground and give it the data from the keyboard.

That first line contains information about the background process - the job number and the process
ID. You need to know the job number to manipulate it between the background and the foreground.

Press the Enter key and you will see the following
[1] + Done ls ch*.doc &
$
The first line tells you that the ls command background process finishes successfully. The second is a
prompt for another command.

Listing Running Processes


It is easy to see your own processes by running the ps (process status) command as follows.
$ps
PID TTY TIME CMD
18358 ttyp3 00:00:00 sh
18361 ttyp3 00:01:31 abiword
18789 ttyp3 00:00:00 ps
32 | Operating System

One of the most commonly used flags for ps is the -f( f for full) option, which provides more
information as shown in the following example.

$ps -f

UID PID PPID C STIME TTY TIME CMD

amrood 6738 3662 0 10:23:03 pts/6 0:00 first_one

amrood 6739 3662 0 10:22:54 pts/6 0:00 second_one

amrood 3662 3657 0 08:10:53 pts/6 0:00 -ksh

amrood 6892 3662 4 10:51:50 pts/6 0:00 psf

Here is the description of all the fields displayed by ps -f command.


UID: User ID that this process belongs to (the person running it)

PID: Process ID

PPID: Parent process ID (the ID of the process that started it)

C: CPU utilization of process

STIME: Process start time

TTY: Terminal type associated with the process

TIME: CPU time taken by the process

CMD: The command that started this process

There are other options which can be used along with ps command.
-a: Shows information about all users

-x: Shows information about processes without terminals

-u: Shows additional information like -f option

-e: Displays extended information

Stopping Processes
Ending a process can be done in several different ways. Often, from a console-based command,
sending a CTRL + C keystroke (the default interrupt character) will exit the command. This works
when the process is running in the foreground mode. If a process is running in the background, you
should get its Job ID using the ps command. After that, you can use the kill command to kill the
process as follows.

$ps -f

UID PID PPID C STIME TTY TIME CMD


Case Study | 33

amrood6738 3662 0 10:23:03 pts/6 0:00 first_one

amrood6739 3662 0 10:22:54 pts/6 0:00 second_one

amrood3662 3657 0 08:10:53 pts/6 0:00 -ksh

amrood6892 3662 4 10:51:50 pts/6 0:00 ps -f

$kill 6738

Terminated

Here, the kill command terminates the first_one process. If a process ignores a regular kill command,
you can use kill -9 followed by the process ID as follows.

$kill -9 6738

Terminated

Parent and Child Processes


Each UNIX process has two ID numbers assigned to it: The Process ID (pid) and the Parent process
ID (ppid). Each user process in the system has a parent process. Most of the commands that you run
have the shell as their parent. Check the ps -f example where this command listed both the process ID
and the parent process ID.

Zombie and Orphan Processes


Normally, when a child process is killed, the parent process is updated via a SIGCHLD signal. Then
the parent can do some other task or restart a new child as needed. However, sometimes the parent
process is killed before its child is killed. In this case, the "parent of all processes," the init process,
becomes the new PPID (parent process ID). In some cases, these processes are called orphan
processes.

When a process is killed, a ps listing may still show the process with a Z state. This is a zombie or
defunct process. The process is dead and not being used. These processes are different from the
orphan processes. They have completed execution but still find an entry in the process table.

Daemon Processes
Daemons are system-related background processes that often run with the permissions of root and
services requests from other processes. A daemon has no controlling terminal. It cannot open
/dev/tty. If you do a "ps -ef" and look at the tty field, all daemons will have a ? for the tty.

To be precise, a daemon is a process that runs in the background, usually waiting for something to
happen that it is capable of working with. For example, a printer daemon waiting for print
commands. If you have a program that calls for lengthy processing, then its worth to make it a
daemon and run it in the background.
34 | Operating System

The top Command


The top command is a very useful tool for quickly showing processes sorted by various criteria.

It is an interactive diagnostic tool that updates frequently and shows information about physical and
virtual memory, CPU usage, load averages, and your busy processes.

Here is the simple syntax to run top command and to see the statistics of CPU utilization by different
processes.

$top
Input and Output Operations:
The shell and many UNIX commands take their input from standard input (stdin), write output to
standard output (stdout), and write error output to standard error (stderr). By default, standard input
is connected to the terminal keyboard and standard output and error to the terminal screen.

The way of indicating an end-of-file on the default standard input, a terminal, is usually <Ctrl-d>.

Redirection of I/O, for example to a file, is accomplished by specifying the destination on the
command line using a redirection metacharacter followed by the desired destination.

C Shell Family
Some of the forms of redirection for the C shell family are:

Character Action

> Redirect standard output

>& Redirect standard output and standard error

< Redirect standard input

>! Redirect standard output; overwrite file if it exists

>&! Redirect standard output and standard error; overwrite file if it


exists

| Redirect standard output to another command (pipe)

>> Append standard output

>>& Append standard output and standard error

The form of a command with standard input and output redirection is:
% command -[options] [arguments] <input file >output file
Case Study | 35

If you are using csh and do not have the noclobber variable set, using > and >& to redirect output
will overwrite any existing file of that name. Setting noclobber prevents this. Using >! and >&!
always forces the file to be overwritten. Use >> and >>& to append output to existing files.

Redirection may fail under some circumstances: 1) if you have the variable noclobber set and you
attempt to redirect output to an existing file without forcing an overwrite, 2) if you redirect output to
a file you don't have write access to, and 3) if you redirect output to a directory.

Examples:
% who > names
Redirect standard output to a file named names
% (pwd; ls -l) > out
Redirect output of both commands to a file named out
% pwd; ls -l > out
Redirect output of ls command only to a file named out
Input redirection can be useful, for example, if you have written a FORTRAN program which
expects input from the terminal but you want it to read from a file. In the following example, myprog,
which was written to read standard input and write standard output, is redirected to read myin and
write myout:

% myprog<myin>myout
You can suppress redirected output and/or errors by sending it to the null device, /dev/null. The
example shows redirection of both output and errors:

% who >& /dev/null


To redirect standard error and output to different files, you can use grouping:
% (cat myfile>myout) >&myerror
Bourne Shell Family
The Bourne shell uses a different format for redirection which includes numbers. The numbers refer
to the file descriptor numbers (0 standard input, 1 standard output, 2 standard error). For example, 2>
redirects file descriptor 2, or standard error. &n is the syntax for redirecting to a specific open file.
For example, 2>&1 redirects 2 (standard error) to 1 (standard output); if 1 has been redirected to a
file, 2 goes there too. Other file descriptor numbers are assigned sequentially to other open files, or
can be explicitly referenced in the shell scripts. Some of the forms of redirection for the Bourne shell
family are:

Character Action
> Redirect standard output
36 | Operating System

2> Redirect standard error


2>&1 Redirect standard error to standard output
< Redirect standard input
| Pipe standard output to another command
>> Append to standard output
2>&1| Pipe standard output and standard error to another
command

Note that < and > assume standard input and output, respectively, as the default, so the numbers 0
and 1 can be left off. The form of a command with standard input and output redirection is:

$ command -[options] [arguments] <input file >output file


Redirection may fail under some circumstances: 1) if you have the variable noclobber set and you
attempt to redirect output to an existing file without forcing an overwrite, 2) if you redirect output to
a file you don't have write access to, and 3) if you redirect output to a directory.

Examples:
$ who > names
Direct standard output to a file named names
$ (pwd; ls -l) > out
Direct output of both commands to a file named out
$ pwd; ls -l > out
Direct output of ls command only to a file named out
Input redirection can be useful if you have written a program which expects input from the terminal
and you want to provide it from a file. In the following example, myprog, which was written to read
standard input and write standard output, is redirected to read myin and write myout.

$ myprog<myin>myout
You can suppress redirected output and/or error by sending it to the null device, /dev/null. The
example shows redirection of standard error only:

$ who 2> /dev/null


To redirect standard error and output to different files (note that grouping is not necessary in Bourne
shell):

$ cat myfile>myout 2>myerror


Case Study | 37

8.4 Summary

Linux is a version of the UNIX operating system. Nowadays it has gained a lot of popularity. Linux
almost resembles a UNIX system in appearance and working. The important features of Linux are
that it is portable. Linux is a multiuser system. Its source code is freely available and it also supports
multiprogramming. Basically, Linux Kernel architecture to be divided into two levels User Space
and Kernel Space. The functions of Linux kernel are process management, memory management,
device control networking etc. The advantage of Linux over operating systems such as Windows is
that security flaws are caught before they become an issue for the public.The UNIX operating system
is a set of programs that act as a link between the computer and the user. The computer program that
allocates the system resources and coordinates all the details of the computer's internals is called the
operating system or the kernel. The advantages of Unix are that it is a multiuser and multitasking
system. Most UNIX installations tend to be much less demanding on system resources. Much of the
backbone of the Internet is run by UNIX servers.

8.5 Exercise

1. Which of the following OS is not based on Linux?


A. Ubuntu B. Redhat C. Centos D. BSD

2. System structure of Linux is

A. Microsoft Windows B. Unix

C. Window Vista D. Monolithic Kernel

3. Unix is written in

A. C language B. Ada language C. Perl language D. Pascal language

4. In Linux a user can load or upload

A. I/O Modules B. I/O Devices C. Kernel Modules D. File Base I/O

5. Which command is used to get the kernel version in Linux?

A. uname r B. kernel C. uname n D. uname s

6. Which command is/are used to remove directory in Linux?

A. Rmdir B. rm r C. only B D. Both A and B

7. Which of the following command is used to create file in Linux?

A. Touch B. Cat C. Echo D. All of the above

8. In Linux everything stored as a

A. File B. Directory C. Executables D. None of the above


38 | Operating System

9. Which command in LINUX is concerned with backup?

A. tar B. zip C. cpio D. untar

10. The dmesg command

A. Shows user login logoff attempts B. Shows the syslog file for info messages

C. kernel log messages D. Shows the daemon log messages

11. find / -name * will

A. List all files and directories recursively starting from /

B. List a file named * in /

C. List all files in / directory

D. List all files and directories in / directory

12. Write about Linux Kernel system

13. List down the components of a Linux System.

14. What is buddyheap algorithm?

15. What is VMware on Linux?

16. What is Linux multifunction server?

17. What is kernel Synchronization in Linux?

18. What is Linux ex2fs file system?

19. What are the security groups in Linux?

20. Explain system administration requirement for Linux system administrator.

21. Explain in detail about VM Ware on Linux Host and Adding Guest OS.

22. Explain in detail about network structure and security in Linux.

23. How are devices represented in UNIX?

24. In Linux, shared libraries perform many operations central to the operating system. What is the
advantage of keeping this functionality out of the kernel? Are there any drawbacks? Explain
your answer.

25. Brief about the directory representation in UNIX.

26. What are the Unix system calls for I/O?

27. What are links and symbolic links in UNIX file system?
Case Study | 39

28. What are the primary goals of the conict-resolution mechanism used by the Linux kernel for
loading kernel modules?

29. The Linux kernel does not allow paging out of kernel memory. What effect does this restriction
have on the kernels design? What are two advantages and two disadvantages of this design
decision?

30. At one time, UNIX systems used disk-layout optimizations based on the rotation position of
disk data, but modern implementations, including Linux, simply optimize for sequential data
access. Why do they do so? Of what hardware characteristics does sequential access take
advantage? Why is rotational optimization no longer so useful?

31. Multithreading is a commonly used programming technique. Describe three different ways to
implement threads, and compare these three methods with the Linux clone() mechanism. When
might using each alternative mechanism be better or worse than using clones?

8.6 Suggested Readings

1. http://publib.boulder.ibm.com
2. Operating Systems: Internals and Design Principles by William Stallings, Pearson.

Вам также может понравиться