Unit 01
Unit 01
Notes
UNIX and Shell Programming
(Vth Semester, BCA)
Prepared by
Balaram Das
Associate Professor
Unit-I
Introduction to UNIX
3
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.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.
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 :
Advantages:
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 :
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:
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.
• 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
3. Tcsh Shell
4. Korn 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 (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) 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.
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.
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.
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.
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.
Unix is a computer operating system. The salient feature of the Unix Operating system
are as follows
• 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.)
• Dumb Terminals (consisting of keyboard & monitor do not have a hard disk or
memory.
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
Security
(a) At the system start-up level it provides login names and passwords for users.
(b) file protection is provided by granting different permissions to each file. (read,
write, and execute).
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.
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.
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
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.
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.
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.
Command Description
ls Lists the contents of a directory.
grep Searches for patterns in files.
find Searches for files in a directory hierarchy.
$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