What is the Linux Kernel and What Does It Do?
With over 13 million lines of code, the Linux kernel is one of the largest open source projects in the world, but what is a kernel and what is it used for?
So What is the Kernel?
A kernel is the lowest level of easily replaceable software that interfaces with the hardware in our computer. It is responsible for interfacing all of our applications that are running in “user mode” down to the physical hardware, and allowing processes, known as servers, to get information from each other using inter-process communication (IPC).
Different Types of Kernels
There are, of course, different ways to build a kernel and architectural considerations when building one from scratch. In general, most kernels fall into one of three types: monolithic, microkernel, and hybrid. Linux is a monolithic kernel while OS X (XNU) and Windows 7 use hybrid kernels.
Microkernel
A microkernel takes the approach of only managing what it has to: CPU, memory, and IPC. Pretty much everything else in a computer can be seen as an accessory and can be handled in user mode. Microkernels have an advantage of portability because they don’t have to worry if you change your video card or even your operating system so long as the operating system still tries to access the hardware in the same way. Microkernels also have a very small footprint, for both memory and install space, and they tend to be more secure because only specific processes run in user mode which doesn’t have the high permissions as supervisor mode.
Pros
• Portability
• Small install footprint
• Small memory footprint
• Security
Cons
• Hardware is more abstracted through drivers
• Hardware may react slower because drivers are in user mode
• Processes have to wait in a queue to get information
• Processes can’t get access to other processes without waiting
Monolithic Kernel
Monolithic kernels are the opposite of microkernels because they encompass not only the CPU, memory, and IPC, but they also include things like device drivers, file system management, and system server calls. Monolithic kernels tend to be better at accessing hardware and multitasking because if a program needs to get information from memory or another process running it has a more direct line to access it and doesn’t have to wait in a queue to get things done. This however can cause problems because the more things that run in supervisor mode, the more things that can bring down your system if one doesn’t behave properly.
Pros
• More direct access to hardware for programs
• Easier for processes to communicate between each other
• If your device is supported, it should work with no additional installations
• Processes react faster because there isn’t a queue for processor time
Cons
• Large install footprint
• Large memory footprint
• Less secure because everything runs in supervisor mode
Hybrid Kernel
Hybrid kernels have the ability to pick and choose what they want to run in user mode and what they want to run in supervisor mode. Often times things like device drivers and file system I/O will be run in user mode while IPC and server calls will be kept in the supervisor mode. This give the best of both worlds but often will require more work of the hardware manufacturer because all of the driver responsibility is up to them. It also can have some of the latency problems that is inherent with microkernels.
Pros
• Developer can pick and choose what runs in user mode and what runs in supervisor mode
• Smaller install footprint than monolithic kernel
• More flexible than other models
Cons
• Can suffer from same process lag as microkernel
• Device drivers need to be managed by user (typically)
Linux Kernel Architecture
Because the Linux kernel is monolithic, it has the largest footprint and the most complexity over the other types of kernels. This was a design feature which was under quite a bit of debate in the early days of Linux and still carries some of the same design flaws that monolithic kernels are inherent to have.
One thing that the Linux kernel developers did to get around these flaws was to make kernel modules that could be loaded and unloaded at runtime, meaning you can add or remove features of your kernel on the fly. This can go beyond just adding hardware functionality to the kernel, by including modules that run server processes, like low level virtualization, but it can also allow the entire kernel to be replaced without needing to reboot your computer in some instances.
Imagine if you could upgrade to a Windows service pack without ever needing to reboot…
What is Linux Shell?
Computer understand the language of 0's and 1's called binary language.
In early days of computing, instruction are provided using binary language, which is difficult for all of us, to read and write. So in OS there is special program called Shell. Shell accepts your instruction or commands in English (mostly) and if it’s a valid command, it is pass to kernel.
Shell is a user program or it's environment provided for user interaction. Shell is an command language interpreter that executes commands read from the standard input device (keyboard) or from a file.
Shell is not part of system kernel, but uses the system kernel to execute programs, create files etc.
Several shell available with Linux including:
Name of shell
|
Command name
|
Description
|
Bourne shell
|
sh
|
The most basic shell available on all UNIX
systems
|
Korn Shell
|
ksh / pdksh
|
Based on the Bourne shell with enhancements
|
C Shell
|
csh
|
Similar to the C programming language in syntax
|
Bash Shell
|
bash
|
Bourne Again Shell combines the advantages of the
Korn Shell and the C Shell. The default on most Linux distributions.
|
tcsh
|
tcsh
|
Similar to the C Shell
|
sh
The Bourne shell, called "sh," is
one of the original shells, developed for Unix computers by Stephen Bourne at
AT&T's Bell Labs in 1977. Its long history of use means many software
developers are familiar with it. It offers features such as input and output
redirection, shell scripting with string and integer variables, and condition
testing and looping.
ksh
David Korn developed the Korn shell, or ksh,
about the time tcsh was introduced. Ksh is compatible with sh and bash. Ksh
improves on the Bourne shell by adding floating-point arithmetic, job control,
command aliasing and command completion. AT&T held proprietary rights to
ksh until 2000, when it became open source.
bash
The popularity of sh motivated programmers to
develop a shell that was compatible with it, but with several enhancements.
Linux systems still offer the sh shell, but "bash" -- the
"Bourne-again Shell," based on sh -- has become the new default
standard. One attractive feature of bash is its ability to run sh shell scripts
unchanged. Shell scripts are complex sets of commands that automate programming
and maintenance chores; being able to reuse these scripts saves programmers time.
Conveniences not present with the original Bourne shell include command
completion and a command history.
csh and tcsh
Developers have written large parts of the
Linux operating system in the C and C++ languages. Using C syntax as a model,
Bill Joy at Berkeley University developed the "C-shell," csh, in
1978. Ken Greer, working at Carnegie-Mellon University, took csh concepts a
step forward with a new shell, tcsh, which Linux systems now offer. Tcsh fixed
problems in csh and added command completion, in which the shell makes educated
"guesses" as you type, based on your system's directory structure and
files. Tcsh does not run bash scripts, as the two have substantial differences.
No comments:
Post a Comment