0% found this document useful (0 votes)
11 views13 pages

Unit 01

The document provides an overview of UNIX and Shell Programming, detailing its history, architecture, and key components such as the kernel and shell. It compares UNIX with Linux, highlighting differences in licensing, complexity, and community support. Additionally, it discusses various types of kernels, shell functionalities, and features of the UNIX operating system, emphasizing its multi-user and multi-tasking capabilities.

Uploaded by

asishkumarkhora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views13 pages

Unit 01

The document provides an overview of UNIX and Shell Programming, detailing its history, architecture, and key components such as the kernel and shell. It compares UNIX with Linux, highlighting differences in licensing, complexity, and community support. Additionally, it discusses various types of kernels, shell functionalities, and features of the UNIX operating system, emphasizing its multi-user and multi-tasking capabilities.

Uploaded by

asishkumarkhora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1

Notes
UNIX and Shell Programming
(Vth Semester, BCA)

Prepared by

Balaram Das
Associate Professor

Department of CSE, School of Engineering and Technology,

GIET University, Gunupur-765022


2

Unit-I
Introduction to UNIX
3

UNIX and Shell Programming.

1.1 Introduction to UNIX operating system

UNIX (also referred to as UNICS) is a UNiplexed Information Computing System. It is


an Operating System that is capable of handling activities from multiple users at the
same time. Unix originated around in 1969 at AT&T Bell Labs by Ken Thompson and
Dennis Ritchie.

The UNIX operating system is a set of programs that act as a link between the
computer and the user. The computer programs that allocate the system resources
and coordinate all the details of the computer's internals are called 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.

1.2 Difference between Unix and Linux

Differences Linux Unix


Origins Linux was developed in the
Unix was developed in 1969.
1990.
Introduction Linux is free to use. Unix is a licensed OS.
Kernels Less complex than the Unixhold- more complex than the Linux
up kernel. kernel.
Availability Linux is widely used on both Unix is mostly used on servers,
enterprise and personal workstations or PCs.
computers.
Community Linux has a large and active While Unix also has a community,
Support community of developers and it is generally smaller and more
users. focused on enterprise-level users.
bug fixing Unix clients require longer hold up
Threat recognition and solutions
time time, to get the best possible bug-
is very fast.
fixing,and a patch.
File system Linux supports more file systems It also supports file system but
support than Unix. lesser than Linux.
GUI Linux is command-based. It uses Initially, it was command-based
KDE and Gnome UGIs. Other OS, but later Common Desktop
GUI supported are LXDE, Xfce, Environment was created. Most
Unity, Mate. Unix distributions use Gnome.
Operating Linux is just the kernel. So less Unix is a complete package of
system complex. Operating system.
Use Cases It is used everywhere from
It is used on servers, workstations,
servers, PCs, smartphones, and
and PCs.
tablets to mainframes.
Interface Bash (Bourne Again Shell) is the Bourne Shell is default shell for
default shell for Linux. Unix.
Source Code The source is accessible to the The source is not accessible to the
Availability general public. general public.

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.


4

Coding Linux is a Unix clone, that Unix contains a completely different


behaves like Unix but doesn't coding developed by AT&T Labs.
contain its code.
Hardware It is available for more than
It is available on PA-RISC and
Compatibility twenty different types of CPU
Itanium machines.
which also includes an ARM.
Virus It has about 60-100 viruses It has about 85-120 viruses listed
Threats listed to date. to date (rough estimate).
Error Developers from all over the
detection world start working on it
In Unix, users must wait for some
and solution whenever a user posts any kind
time for the problem to be resolved.
of threat. Hence, it provides a
faster solution.
Example Ubuntu, Debian GNU, Arch SunOS, Solaris, SCO UNIX, AIX,
Linux, etc. HP/UX, ULTRIX etc.

1.3 UNIX architecture

• The UNIX architecture has three


important agencies-
• Kernel and shell
• The file and process
• The system calls

1.4 Kernel

The kernel is the heart of the operating system. It interacts with the machine's
hardware. It is a collection of routines mostly written in C. It is loaded into memory
when the system is booted and communicates directly with the hardware.

User programs (the applications) that need to access the hardware use the services of
the kernel, which performs the job on the user's behalf. These programs access the
kernel through a set of functions called system calls.

Apart from providing support to the user's program, the kernel also does important
housekeeping. It manages the system's memory, schedules processes, and decides
their priorities, and so on.

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.


5

Main responsibilities: Memory Management, Process Management and File


Management.

Types of Kernel:

1. Monolithic Kernel
2. Micro Kernel
3. Hybrid Kernel
4. Exo Kernel
5. Nano Kernel

1. Monolithic Kernel
It is one of types of kernel where all operating system services operate in kernel
space. It has dependencies between systems components. It has huge lines of code
which is complex.

Example:
Unix, Linux, Open VMS, XTS-400 etc.

Advantage:
• Monolithic kernels are faster than other types of kernels.
• are simpler to design, implement, and debug.
• have lower latency.
Disadvantage:
• Less stable than other types of kernels.
• can be more difficult to maintain.
• are less modular than other types of kernels
2. Micro Kernel
It is kernel types which has minimalist approach. It has virtual memory and thread
scheduling. It is more stable with less services in kernel space. It puts rest in user
space. It is use in small os.
Example :

Mach, L4, AmigaOS, Minix, K42 etc.

Advantages:

• Microkernel architecture is reliable than monolithic kernels.


• more flexible than monolithic kernels.
• more modular than monolithic kernels.
• more portable than monolithic kernels.
Disadvantages:

• Microkernel architecture can be slower than monolithic kernels.


• more complex than monolithic kernels.

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.


6

• Developing OS, based on microkernel architecture can be more difficult than


developing monolithic kernel OS.
• Microkernel architecture can use more system resources, such as memory
and CPU, than monolithic kernels

3. Hybrid Kernel

It is the combination of both monolithic kernel and microkernel. It has speed and
design of monolithic kernel and modularity and stability of microkernel.
Example :

Windows NT, Netware, BeOS etc.

Advantages:
Hybrid kernels
• can offer better performance than microkernels.
• offer better reliability than monolithic kernels.
• offer better flexibility than monolithic kernels
• Hybrid kernels can be more compatible than microkernels.
Disadvantages:
Hybrid kernels can be
• more complex than monolithic kernels.
• less secure than microkernels.
• more difficult to maintain than microkernels.
• use more system resources than microkernels.

4. Exo Kernel

It is the type of kernel which follows end-to-end principle. It has fewest hardware
abstractions as possible. It allocates physical resources to applications.
Example:

Nemesis, ExOS etc.

Advantages:
Exokernels
• offer the highest level of flexibility.
• designed to provide better performance than traditional kernels
• provide better security than traditional kernels.
• highly modular, allowing for the easy addition or removal of OS services.
Disadvantages:
• Exokernels can be more complex to develop than traditional kernels.
• Developing applications for exokernels can be more difficult than for
traditional kernels.

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.


7

• Exokernels are still an emerging technology and may not have the same level
of support and resources as traditional kernels.
• Debugging applications and operating system services on exokernels can be
more difficult than on traditional kernels.
5. Nano Kernel
It is the type of kernel that offers hardware abstraction but without system services.
Micro Kernel also does not have system services therefore the Micro Kernel and Nano
Kernel have become analogous.
Example:

EROS etc.

Advantages:
Nanokernels are
• designed to be extremely small, providing only the most essential functions
needed to run the system.
• more flexible and customizable than traditional monolithic kernels.
• provide better security than traditional kernels.
• are designed to be highly portable, allowing them to run on a wide range of
hardware architectures.
Disadvantages:
• Nanokernels are unsuitable for more complex applications.
• Nanokernels can be more complex to develop and maintain than other kernel
types.
• Nanokernels are not able to provide the same level of performance as other
kernel types in certain situations.
• Nanokernels may not be compatible with all hardware and software
configurations, limiting their practical use in certain contexts.
1.5 Shell

Computers don't have any capability of translating commands into action. That
requires a command interpreter, also called the shell. Shell acts as an interface
between the user and the kernel. The shell accepts commands from user and
communicates with the kernel to see that the command is executed.

Main Responsibilities:

(a) Interprets the commands the user types in and (b) dispatches the command to the
kernel for execution.

Shell is present in the /bin/sh directory. There are different types of shells. They are

1. Bourne Shell

2. C shell

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.


8

3. Tcsh Shell

4. Korn Shell

5. Bourne again Shell

6. Z shell

Functions of shell:

• File opening.
• File writing.
• Executing programs.
• Obtaining detailed information about the program.
• Termination of the process.
• Getting information about time and date.

The Bourne Shell (sh)

The Bourne Shell (often denoted as sh) has become synonymous with UNIX Shell
scripting. This pioneering Shell offered users a programming environment, complete
with variables, control structures, and built-in operators. Its simplicity was its
strength, ensuring widespread adoption in UNIX environments.

The C Shell (csh)

The C Shell (csh) aimed to offer an improved User Experience. Notably, its syntax
mirrors providing an intuitive environment for those familiar with C. Enhanced
scripting features, including job control and command history, make it quite
interactive.

The Tcsh Shell

Tcsh is an upgraded C shell. This shell can be used as a shell script command
processor and interactive login shell. Tcsh shell includes the following characteristics:

• C like syntax
• Filename completion and programmable word
• Command-line editor
• Job control
• Spelling correction
The Korn Shell (ksh)

It was developed and designed by David G. Korn. Ksh shell is a high-level, powerful,
and complete programming language and it is a reciprocal command language as well
just like various other GNU/Unix Linux shells. The usage and syntax of the C shell are
very same as the C programming language.

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.


9

The Z Shell (zsh)

zsh, was released in 1990, it combined the best of bash, ksh, and tcsh. What
sets zsh apart is its customizability, advanced features such as shared command
history, spelling correction, and themeable prompts. It offers users a tailored Shell
experience. Over the years, zsh has grown in popularity, particularly among
developers and power users. This ascent was further cemented when macOS Catalina
chose zsh as its default Shell. Its dynamic community ensures regular updates,
making zsh a compelling choice for modern users.

The Bourne Again Shell (bash)

In the bash shell, bash means Bourne Again Shell. It is a default shell over several
distributions of Linux today. It is a sh-compatible shell. It could be installed over
Windows OS. It facilitates practical improvements on sh for interactive and
programming use which contains:

• Job Control
• Command-line editing
• Shell Aliases and Functions
• Unlimited size command history
• Integer arithmetic in a base from 2-64
1.6 Files

Two simple entities support UNIX – the file and the process. A file is just an array of
bytes and can contain virtually anything. A file forms a Hierarchical file system. Every
file in UNIX is part of the one file structure provided by UNIX. UNIX considers
directories and devices as members of the file system.

1.7 Processes

The process is the name given to the file when it is executed as a program (Process is a
program under execution). We can say process is the “time image” of an executable
file. UNIX provides tools to control processes move them between foreground and
background and kill them.

1.8 System calls

The UNIX system- comprising the kernel, shell, and applications-is written in C.
Though several commands use functions called system calls to communicate with the
kernel. All UNIX flavors have one thing in common – they use the same system calls.
Eg: write, open.

1.9 Features of UNIX

Unix is a computer operating system. The salient feature of the Unix Operating system
are as follows

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.


10

• Multi-User
• Multi-Tasking
• Portability
• Communication
• Security
• Machine Independent
Multi-User

Several users can use the UNIX System at the same time. So it is called a Multiuser
system. It is a multi-user operating system. It supports multiple users at a time (it
shares resource like printers, hard disks etc.)

The main computer is connected to a number of terminals, which in turn consist of a


keyboard and monitor. There are several types of terminals that can be connected to
the server. They are

• Dumb Terminals (consisting of keyboard & monitor do not have a hard disk or
memory.

• Terminals Emulator(consist of own memory, MP and disk drive it to transmit its


job to a server for processing)

• Dial in terminals (Connect to server through telephone lines

Multi tasking

A user can run multiple programs at the same time so UNIX is called as Multitasking.
This feature enables Unix OS to support concurrent execution of multiple processes.
Each command takes small fraction of times to process.

Portability

Unix is highly portable and can easily be implemented on different hardware platforms
since it is written in C language. The Unix operating system is highly portable. It can
easily be implemented on different hardware platforms with little or no modification.

Communication

It is highly effective in Unix. Communication can be established between users


working on different terminals connected to the network. The Users can easily
exchange mail, data, or programs through the network.

Security

UNIX provides security at various levels.

(a) At the system start-up level it provides login names and passwords for users.

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.


11

(b) file protection is provided by granting different permissions to each file. (read,
write, and execute).

(c) Unix supports file encryption (unreadable format).

Machine Independent

The System hides the machine architecture from the user. So it is easier to write a
program that runs on different hardware implementations. Unix OS treats everything
including memory and I/O devices as files. The Unix file system allows easy and
efficient maintenance of files.

Other features of UNIX

Programming Facility: The UNIX Operating System also provides programming


languages such as Shell Programming and Perl programming

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. Utilities are
powerful tools that perform a special task. Some of the utilities are awk, grep, sed, cp,
etc.

UNIX shell: UNIX has a simple user interface called the shell that has the power to
provide the services that the user wants.

Hierarchical File System: UNIX uses a hierarchical file structure to store


information. It allows for easy maintenance and efficient implementation. Unix File
System can be Local or Distributed.

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.

Windowing System: XWINDOWS is the first Graphical User Interface for UNIX. It
supports network applications and also can use multiple windows to run the
programs

1.10 POSIX and single-user specification

The Portable Operating System Interface (POSIX) is a family of standards specified by


IEEE for maintaining compatibility between operating systems. Two of the most
important standards from POSIX are:

1) POSIX.1 – Specifies the C application program interface – the system calls


(Kernel)

2) POSIX.2 – Deals with the Shell and utilities

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.


12

In 2001, a joint initiative of X/Open and IEEE resulted in the unification of two
standards. This is the Single UNIX Specification, Version 3 (SUSV3). The “Write once,
adopt everywhere” approach to this development means that once software has been
developed on any POSIX machine it can be easily ported to another POSIX compliant
machine with minimum or no modification.

1.11 Internal and external commands

Internal commands:

Commands which are built into the shell are known as internal commands. For all the
shell built-in commands, execution of the same is fast in the sense that the shell
doesn’t have to search the given path for them in the PATH variable, and also no
process needs to be spawned to execute it.

Examples: source, cd, fg, etc.

Top 5 Internal Commands

Command Description
cd Changes the current directory.
echo Displays a line of text or variable value.
exit Exits the current shell session.
pwd Prints the current working directory.
alias Creates an alias for a command.

External commands:

Commands which aren’t built into the shell are known as External commands. When
an external command has to be executed, the shell looks for its path given in the
PATH variable, and also a new process has to be spawned and the command gets
executed. They are usually located in /bin or /usr/bin. For example, when you
execute the “cat” command, which usually is at /usr/bin, the executable /usr/bin/cat
gets executed.

Examples: ls, cat etc.

Top 5 External Commands

Command Description
ls Lists the contents of a directory.
grep Searches for patterns in files.
find Searches for files in a directory hierarchy.

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.


13

cp Copies files and directories.


mv Moves or renames files and directories.
How to find out whether a command is internal or external?
In addition to this you can also find out about a particular command i.e whether it is
internal or external with the help of the type command :
$type cat
cat is /bin/cat

//specifying that cat is


external type//

$type cd
cd is a shell builtin

//specifying that cd is
internal type//
Getting the list of Internal Commands
If you are using bash shell you can get the list of shell built-in commands
with help command:
$help

//This will list all


the shell built-in commands //

Prepared by Balaram Das, Dept. of CSE, SoET, GIET University, Gunupur.

You might also like