Академический Документы
Профессиональный Документы
Культура Документы
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
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.
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.
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.
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.
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.
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
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.
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
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
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.
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.
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.
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.
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.
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
Table 8.2: System requirements for ESM manager+agent and ESM agent on UNIX computers
Swap space 4 GB 1 GB
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.
1. Enter your username at the login prompt. If you make a mistake, use the Delete key or
Backspace key to correct it.
login: larry
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.
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
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.
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:
Directory Description
less filename: Browses through a file from the end or the beginning
more filename: Browses through a file from the beginning to the end
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
Command& Description
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.
Server A
1. Define a device class with a device type of FILE.
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
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.
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
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
You can customize your command prompt using the environment variable PS1 explained in the
Environment tutorial.
C shell If you are using a C-type shell, the % character is the default prompt.
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.
$ 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
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
in Cape Town.
EOF
You can use the here document to print multiple lines using your script as follows
#!/bin/sh
in Cape Town.
EOF
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
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
After running the script, you should see the following added to the file test.txt
$ cat test.txt
a shell script
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.
#! /usr/bin/env bash
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.
#! /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
$ cd /home/pbmac/scripts
$ ./myscript
or
$ /home/pbmac/scripts/myscript
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
$ source ./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.
There are various options which you can use along with the grep command description.
1. -v: Prints all lines that do not match pattern.
3. -l: Prints only the names of files with matching lines (letter "l")
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".
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
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.
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.
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.
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
PID: Process ID
There are other options which can be used along with ps command.
-a: Shows information about all users
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
$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
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
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
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:
Character Action
> Redirect standard output
36 | Operating System
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:
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:
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
3. Unix is written in
A. Shows user login logoff attempts B. Shows the syslog file for info messages
21. Explain in detail about VM Ware on Linux Host and Adding Guest OS.
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.
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?
1. http://publib.boulder.ibm.com
2. Operating Systems: Internals and Design Principles by William Stallings, Pearson.