Linux/Unix Shell, Kernel & Shell Scripts

0
50

Linux Kernel is the main component of a Linux operating system (OS) and is the core interface(communication) between a computer’s hardware and its processes. It manages operations(memory and CPU time) of computer and hardware. Kernel acts as a bridge between applications and data processing performed at hardware level using inter-process communication and system calls.

It is responsible for various tasks such as disk management, task management, and memory management.

Kernel loads first into memory when an operating system is loaded and remains into memory until operating system is shut down again.

It decides which process should be allocated to processor to execute and which process should be kept in main memory to execute. The major aim of kernel is to manage communication between software like user-level applications and hardware like CPU and disk memory.

Objectives of Kernel :

  • To establish communication between user level application and hardware.
  • To control disk management.
  • To control memory management.
  • To control task management.

Types of 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 complex lines of code.

Example : Unix, Linux, Open VMS, XTS-400 etc.
Advantage : It has good performance.
Disadvantage : It has dependencies between system component and lines of code in millions.

  1. Micro Kernel – A kernel with 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.

Example : Mach, L4, AmigaOS, Minix, K42 etc.
Advantage : It is more stable.
Disadvantage : There are lots of system calls and context switches.

  1. Hybrid Kernel – A 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.
Advantage : It combines both monolithic kernel and microkernel.
Disadvantage : It is still similar to monolithic kernel.

  1. 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.
Advantage : It has fewest hardware abstractions.
Disadvantage : There is more work for application developers.

  1. 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.
Advantage : It offers hardware abstractions without system services.
Disadvantage :It is quite same as Micro kernel hence it is less used.

Unix/Linux shell – A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems.

It helps user to interact with kernel. it takes input from user and translate it to machine language and process it at OS level

Shell like ksh, csh, bash etc. Utilities like vi, cat, grep, git etc

There are two kinds of shell

  1. Command Line Shell – which is accessible by command line interface like terminal in linux and max or cmd of windows. Command are accepted by command line and result is displayed on terminal to user.
  2. Graphical Shell – It provides means for manipulating operations and programs based on graphical user interface (GUI).

Linux Shells

  • BASH (Bourne Again SHell) – Widely used shell in Linux systems as default login shell in Linux and macOS. It can also be installed on Windows OS.
  • CSH (C SHell) – The C shell’s syntax and usage are very similar to the C programming language.
  • KSH (Korn SHell) – The Korn Shell also was the base for the POSIX Shell standard specifications.
  • GNOME- GNU Network Object Model Environment/Shell
  • KDE Plasma – GUI shell.

Command Line Shell accepts commands one by one through its command line. Some time we want to run multiple command line sequence where input and output of commands can be supplied across various command using variables. For this we can write all such command with their respective variables in a file. This file is called Shell Script. a shell script can have keywords, commands, functions and control flow elements.

Usage Of Shell scripts

  1. For Automation and Reusability by avoiding rewriting resistive work.
  2. For users to perform various routine tasks like system monitoring, backup and executions.
  3. Adding new functionality

Advantages

  1. Automation, Reusability and Quick Coding.
  2. Managing Environment

Disadvantages

  1. Design flaws and slow execution speed, not suitable for larger tasks.
  2. Very difficult to debug.

Sample Shell Script

File Naming – name should be a valid file name ending with .sh like run.sh
Shebang – shebang is used to tell the kernel which interpreter should be used to run the commands present in the file. It is a character sequence consisting of the characters number sign and exclamation mark (#!) at the beginning of a script. It is also called sha-bang, hashbang, pound-bang or hash-pling. The shebang line is usually ignored by the interpreter, because the “#” character is a comment marker in many scripting languages.

#!/bin/sh   # shebang

# Author : Vishal Bhandari
# this is a line comment, ignored by kernel

echo "What is your name?"
read PERSON
echo "Hello, $PERSON"

to execute this script, User must have execute permission.

$ chmod +x run.sh
$ ./run.sh
What is your name?
Vishal 
Hello, Vishal
$
Previous articleSharing Windows Folder To Linux Virtual Box OS
Next articleLinux Commands
Vishal Bhandari is an admin, editor and writer of this portfolio. He writes about himself, his interests, hobbies, activities. He manages many articles about tech, finance, history and geopolitics on his portfolio.

LEAVE A REPLY

Please enter your comment!
Please enter your name here