Kernel

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Kenel and unix commands

 Layer-1: Hardware-This layer consists of all the hardware resources being used.
 Layer-2: Kernel -The kernel is like the heart of the operating system. It is the mode
of interaction between the hardware and the operating system. It also manages tasks
and resources using scheduling processes for the smooth functioning of the system.
 Layer-3: Shell commands -It is how a human interacts with the operating system and
tells it to start certain processes. An interpreter is used where we give the command
for the operating from the set of all commands for which the definition has been
defined and stored in the libraries.
Some examples of commands are cp, mv, cat, grep, id, wc, nroff, a.out, and more.
 Layer-4: Application Layer -It executes the given external applications. It is the
outermost layer to execute the applications.
List of Unix Shell Commands-Here is the list of the following Unix Shell Commands
mention below:
 Basic.
 Intermediate.
 Advanced.
1. Basic Unix Shell Commands
a. Listing files (ls) – ‘ls’ command lists all the files in a directory.
Syntax- ls -<option> directory_name
Example-ls test

option Description

ls -a To list all files with the hidden files starting with ‘.’

ls –color Shows colored list which can be [=always/never/auto]

ls -d To list all directories

ls -F To add one char to the entries

ls -i To list all files ignoring the case


ls -l To list all the details of the file

ls -la list long format, including hidden files

ls -lh list long format with the readable file size

ls -ls list with the long format with the file size

ls -r list in reverse order

ls -R list directory tree recursively

ls -s list file size

ls -S sort by file size

ls -t sort by time & date

ls -X sort by extension name

b. Creating & Viewing Files – ‘cat command can be used to create the file or view the
contents of the file.
Syntax –cat >filename
Example – cat > test1.dat – will create a file and wait for the input to be written into the file.
cat filname – will display the contents of the file on the screen.
c. Deleting Files -‘ rm’ command deletes a file from the directory.
Syntax-rm filename

Tag Description

-f, –force ignore nonexistent files, never prompt.

-i prompt before every removal.


d. Moving and Re-naming files – ‘mv’ command is used for moving a file from one
location to another. This command can also be used to rename the file as the source file gets
deleted and a new file is created.
Syntax–mv <source_file> <target_file>
Example – mv test1.dat test2.dat – here, contents of the test1 file get copied to test2.dat in
the same directory, and the test1.dat file gets deleted.
e. Making directories – Unix also provides us with the command to make our own directory.
It is just like making our own folder where all relevant files can be stored.
Syntax –
mkdir <dir_name>
Example – mkdir /abi/sand/results – this command will create a directory at /abi/sand path .
This command will not work if /abi/sand/ path does not exist.
2. Intermediate
a. Chmod – Sometimes, when we write into a write-protected file, we need to change the
permissions given to a file or directory. Here ‘chmod’ command is used to give suitable
permissions. But one should know the pattern for giving permissions.
Permissions are given as rwxrwxrwx
We must set permission to 1 if we need to enable it and 0 if it needs to be disabled.
For instance, if one wants to only read and execute permissions to users and others but all
permissions to the group. Then we must set it as ‘101111101’. And that means ‘575’ if
converted to decimal in triplets. Thus for giving permissions, we give the command as
Example –
chmod 575 file1.dat
b. Find – This command finds the files or directories and subdirectories in a particular
directory.
Syntax –find <options> <paths>
Example –

Option Description

-atime n Returns true if the file was accessed n days ago

-ctime n Returns true if the file was changed n days ago

-mtime Returns true if file contents were modified n days ago

-name Return true if filename matching a particular pattern

-size Returns true if the file size is n blocks.

-type c Returns true if the file being searched is of type c( if c = ‘f’ means it is a file; if it ‘d’,
means it is a directory)
Example – If someone wants to search for file names ‘test1’ in the directory, he should give
a command like –
find –type f –name test1 /abi/sand
– This command will give all test1 file in /abi/sand directory
c. chown – change ownership of the file. Sometimes someone wants to change the file owner
so that someone working on that file can access that file. Only the file owner has the right to
change the file ownership.
Syntax:chown [owner] [file]
Example: Change the owner of test1 to user name ‘aaggasa’, assuming that the current user
currently owns it
> chown aaggasa test1
d. chgrp: change the group ownership of the file. This command is used to change the group
to which the file belongs. Only the file owner has the right to change the file ownership.
Syntax:chgrp [group] [file]
Example: Change the group of test1 to group2, assuming the current user currently owns it.
> chgrp group2 test1
e. Head: Unix gives us this command-line utility to extract the first part of the file. It writes
the result on standard output.
Syntax –head <option> <filename>
Option Description

-n Used to specify the number of lines to be fetched

–c Used to specify the number of bytes to be fetched.

-q Used to suppress the header line.


Example – If someone wants to extract the first 5 lines of the file, we must use
>head –n 5 /abi/sand/test1.dat
Note – By default, UNIX will show 10 lines in case no option is specified with the head
command.
f. Tail: Unix gives us this command-line utility to extract the first part of the file. It writes the
result on standard output.
Syntax –tail <option> <filename>

Option Description

-n Used to specify the number of lines to be fetched

–c Used to specify the number of bytes to be fetched.

-q Used to suppress the header line.


Example – If someone wants to extract the first 5 lines of the file, we must use
>head –n 5 /abi/sand/test1.dat
Note – By default, UNIX will show 10 lines in case no option is specified with the head
command.
3. Advanced Unix Shell Commands
a. Grep: This command utility helps search a particular pattern or character in the file. It
returns all the lines that match the pattern in that particular file.
Syntax-grep <options> <pattern> <files>

Option Description

-n Display the matched lines and their line numbers.

-v To print the lines that do not match the pattern.

-l To display the list of filenames.

-c The count of lines that matches the pattern can be extracted.

-h Display the matched lines, but do not display the filename

-i Ignores, the case for matching

-w To Match the whole word in the expression


b. ln: make links and symlinks to files and directories. A symbolic link comprises a special
type of file containing a reference to another file. This helps to create a link between files.
There are 2 types of links”-
1. Soft link – It refers to the abstract path to a file.
2. Hard Link – It refers to the exact location of that file,
To create a soft link ‘ln’ command is used.
Syntax –
ln -s {source_filename} {symbolic_filename}
Example – If we want to create a softlink link l1 to the path ‘/abi/sand/dir1’, then we must
execute the following command:-
>ln link1 /abi/sand/dir1
This command will create a link to the directory in the current directory
To check the link execute-
ls –l
Output – lrwxrwxrwx 1 priya priya 16 2007-09-25 22:53 link1 -> /abi/sand/dir1
c. cut – This command utility extracts a particular column from a file. To extract a column,
we need to specify the delimiter to help distinguish the columns in that file.
Syntax–cut <options> <file>

Option Description

-c For fixed-width fields, the -c option is used.

-d For specifying the delimiter. By default, the delimiter is a tab.

-b For specifying the number of bytes to be extracted

-f For specifying the field number that needs to be extracted.


Example – If someone wants to extract the second field from the ‘city.txt’ file where ‘|’ is
treated as a delimiter for the columns.
cut –d "|" –f 2 city.txt
Conclusion
Unix Commands are a powerful tool that helps users execute the processes and do various
tasks they want. Its inbuilt parser helps in development using various scripting languages.
With its powerful set of commands utility, one can perform all the features that need to be
read from registers.
Kernel in Operating System
What is Kernel in OS
The kernel is a pivotal component at the heart of an operating system, with the critical role of
managing and controlling hardware and software operations. It oversees essential functions
such as CPU time and memory management as the core element. Serving as the vital link
between applications and hardware, it employs interprocess communication and system calls
to facilitate data processing. When the operating system boots, the kernel is the first
component loaded into memory, and it continues to operate as long as the system is running,
managing tasks such as memory, disk access, and process management. The kernel maintains
a process table that tracks active processes and utilizes the ‘exec’ system call to load files into
memory. Its primary objective is to allocate CPU and main memory resources for process
execution efficiently. It is an indispensable interface facilitating communication between
user-level software applications and hardware (CPU and disk memory).
Table of Contents
 What is Kernel in OS
 Objective of Kernel
 Benefits and Challenges of Kernel in Operating System
 Modes in Operating System
o User Mode
o Kernel Mode
 Difference between User Mode and Kernel Mode
 Real-life Scenarios
 Types of Kernel
 Kernel vs Operating System
A. Objective of Kernel
The main goal of the kernel is to run and provide security to your computer. These are
important purposes of the kernel in operating systems.
1. Scheduling Processes
Kernel does process scheduling Processes. Kernel decides which tasks happen when. It gives
time to different jobs and starts new ones when old ones are finished. The kernel can also
check if jobs are running, waiting, and completed.
2. Resource Allocation
Another big job of the kernel is Resource Allocation. The kernel decides who gets to use
memory, parts, and power. Kernel is like a traffic cop, which makes sure everything gets
where it needs to go.
3. Device Management
The kernel also takes care of Device Management. The kernel looks after the computer tools
like printers and hard drives. It helps them talk to the programs and makes sure information
moves around the computer smoothly.
4. Interrupt Handling and System Calls
When something special happens and a program needs help, the kernel does Interrupt
Handling and System Calls. It determines what is most important and helps programs talk to
the computer.
5. Memory Management
Memory is like the desk of a computer. The job of a kernel in Memory Management is to
organize it. It ensures each program gets enough space and cleans up when finished.
6. Process Management
Kernel is the boss of Process Management. It makes sure programs start, run, and finish
correctly. It is like an orchestra conductor, so make sure every part plays together.
Hence, the objective of Kernel is to connect your application with the computer hardware.
Working of Kernel in Operating System
The Kernel is like the brain of your computer, which controls everything from applications to
security. It is essential for running and safeguarding your system, managing files, and
preventing unauthorized access. The Kernel communicates with hardware through system
calls.
B. Benefits and Challenges of Kernel in Operating System
Kernel have various benefits in operating systems. The kernel manages resources like
memory, processors, and devices for better performance. It provides services for security,
multitasking, and communications. Kernel also handles tasks like suspending and terminating
processes, which ensures stability and security.
Despite benefits, Kernel considerations include device-specific requirements and have
challenges for developers unfamiliar with hardware nuances. The Kernel is critical and
vulnerable to attacks. They exploited and unauthorized access risks system damage and data
theft.
C. Modes in Operating System
There are two modes in operating systems: user mode and kernel mode.

1. User Mode
The system is in user mode when you use applications like MS Word (mode bit 0). It
switches to kernel mode (mode bit 1) when accessing devices and system calls.
2. Kernel Mode
At boot, the system starts in kernel mode. Applications run in user mode. Switch to kernel
mode happens for interrupts, privileged instructions, and device access. The mode bit
changes from 0 to 1 when returning to user mode.
D. Difference between User Mode and Kernel Mode

Section Kernel Mode User Mode

Resource Access Direct access to RAM and No direct access; requires a system call for
hardware. access.

Modes Also known as master, privileged, Also known as unprivileged, slave, or


or system mode. restricted mode.

Privilege Level More privilege for accessing Less privilege for accessing resources.
resources.

Virtual Address All processes share the virtual Processes share a separate virtual address
Space address space. space.

Restrictions No restrictions; direct access to user Restricted; needs a system call for
and kernel programs. immediate access.

Mode Bit Value Mode bit set to 0. Mode bit set to 1.

Interruptions System shutdown is possible on Single process failure doesn’t shut down
interruption during execution. the whole system.
System Crash Single-system crashes may lead to A single system crash is recoverable and
complicated problems. doesn’t affect the whole system process.

Functionality You can refer to any memory block Basic; cannot access hardware/RAM
and access resources directly. directly, uses API.
E. Real-life Scenarios
In everyday situations, you may encounter errors generated by the Kernel. For instance, when
attempting to download a file, you might receive an error message (error-1) warning that the
file could harm your computer. This caution from the Kernel is based on its foresight of
potential problems that may arise during the download, or it could be due to the unavailability
of necessary resources for the download process.
F. Types of Kernel in OS
There are five types of kernels, as given below.
1. Monolithic Kernel
Monolithic Kernels handle core computer functions, managing files, memory, and resources.
Examples are Dos, Solaris, and Linux. Monolithic kernels are used for tasks like CPU
scheduling and are known for reliability, security, and speed. All hardware control software is
within the kernel for direct communication. Monolithic kernels can load modules efficiently
and reduce overhead compared to embedded modules.
Examples of Monolithic kernels are Linux, Unix, XTS-400, and VMS.

G. Advantages of Monolithic Kernel


These are the advantages of Monolithic Kernel:
1. Efficiency: Monolithic Kernels are faster because there are fewer mode switches
during system calls. It has reduced overhead.
2. Tight Integration: Operating system services communicate efficiently. You can
implement complex functionalities and optimizations quickly.
3. Simplicity: A monolithic kernel is easier to design, implement, and debug. It has a
unified structure for code management.
4. Lower Latency: Monolithic Kernels handles system calls and interrupts directly. So,
it has lower latency compared to other kernel types.
Disadvantages of Monolithic Kernel
These are the disadvantages of Monolithic Kernels:
1. Stability Issues: There are bugs and security issues in a service that can affect the
whole system.
2. Security Vulnerabilities: Monolithic Kernels can have vulnerabilities in one service,
which can compromise the entire system.
3. Maintenance Difficulties: Any changes in one service can impact the entire system.
It can be challenging to maintain.
4. Limited Modularity: Monolithic Kernels are less modular and tightly integrate
services into kernel space. It is tough to add and remove functionality without
affecting the system.
2. Microkernel Kernel
A microkernel manages files, memory, and process tasks like a monolithic kernel. It is
smaller, allocating space for functions like file sharing and scheduling. Each service has its
address, reducing overall OS size.

The central concept is reliability through smaller modules. Microkernels allow


communication between client programs and user-space services. Adding new services does
not modify the kernel, ensuring high security, as service failures do not impact the OS.
Examples of Microkernel kernels are Minix, K42, Mach, AmigaOS, and L4.
Advantages of Microkernel
1. Reliability: Microkernels are designed for more reliability. The service issues do not
affect the entire system.
2. Flexibility: Microkernels are more flexible than monolithic kernels. The services can
be added and removed without system impact.
3. Modularity: Microkernels have a modular design. Each service runs independently
for easier maintenance.
4. Portability: Microkernels are more portable than monolithic kernels. The services
outside the kernel space have adaptations for different hardware.
Disadvantages of Microkernel
1. Performance: Microkernels are slower due to increased context switches between
user and kernel space.
2. Complexity: Microkernels have complex designs with additional communication and
synchronization mechanisms.
3. Development Difficulty: These are harder to develop due to intricate communication
and synchronization design.
4. Higher Resource Usage: Microkernel uses more memory and CPU due to increased
communication and synchronization needs.
3. Hybrid Kernel
Hybrid kernel mix monolithic and microkernel features for improved performance. Unlike
pure microkernels, they decide which components stay inside the kernel and which go
outside. XNU influenced Apple’s MacOS, IOS, WatchOS, and tvOS. They can not load
runtime modules, enhancing performance and reducing vendor lock-in. Hybrid kernel
development begins as monolithic and progressively shifts components to user-land.
Examples of Hybrid kernels are BeOS, Windows WT, and Netware.

Advantages of Hybrid Kernel


1. Performance: Hybrid Kernel performs better with fewer context switches between
user and kernel space.
2. Reliability: Hybrid Kernel improved reliability by isolating drivers and kernel
components in separate protection domains.
3. Flexibility: Hybrid Kernel has enhanced flexibility. These also support adding and
removing services without impacting the entire system.
4. Compatibility: Hybrid Kernel is more compatible and supports a broader range of
device drivers.
Disadvantages of Hybrid Kernel
1. Complexity: Hybrid Kernel is more complex to design with monolithic and
microkernel components.
2. Security: Due to monolithic components, Hybrid Kernel is less secure with a larger
attack surface.
3. Maintenance: Hybrid Kernels are more challenging due to complex design and
implementation.
4. Resource Usage: Hybrid Kernel uses more system resources with a combination of
monolithic and microkernel components.
4. Exokernel
Exokernel OS manages hardware resources at the app level. It isolates protection from
management. Unlike typical OS, you can customize which minimizes abstractions for
improved performance and app support. Developers have direct control over hardware and
setting their preferred levels of abstraction.

Examples of Exokernels are ExOS and Nemesis.


Advantages of Exokernels
1. Flexibility: Exokernels provide the highest flexibility for developers to customize and
optimize for specific applications.
2. Performance: Exokernels provide better performance. It removes unnecessary
abstractions and offers direct access to hardware.
3. Security: Exokernels improve security with fine-grained control over system resource
allocation.
4. Modularity: Exokernels are highly modular. So it is easy to add and remove
operating system services.
Disadvantages of Exokernels
1. Complexity: Exokernels are complex to develop because of detailed resource
allocation considerations.
2. Development Difficulty: Exokernels developed applications can be challenging
because they must directly access hardware.
3. Limited Support: Exokernels may lack the support and resources as traditional
kernels.
4. Debugging Difficulty: In Exokernels, debugging can be more challenging due to
direct access to hardware resources.
5. Nano Kernel
A nanokernel is a small and privileged hardware code with nanosecond clock resolution. An
example of a Nanokernel is KeyKOS, which was introduced in 1983. It has reliability,
security, and continuous software availability. On a single system, it supports several
operating systems. KeyKOS nanokernel uses only 100KB of memory and 20,000 lines of C
code.
An example of a Nano kernel is EROS.
Advantages of Nano Kernel
1. Small Size: Nano Kernels are very small for efficiency and faster operation.
2. High Modularity: Nano Kernels are highly modular for quickly adding and
removing services.
3. Security: Nano Kernel provides better security with a smaller attack surface and
reduced code errors.
4. Portability: Nano Kernels are portable and can run on various hardware
architectures.
Disadvantages of Nano Kernel
1. Limited Functionality: Nano Kernels are unsuitable for complex applications that
require a broader range of services.
2. Complexity: Nano Kernels are complex to develop and maintain due to functionality.
3. Performance: Its design may not match the performance of other kernel types.
4. Compatibility: These are incompatible with all hardware and software configurations
that limit practical use.
H. Kernel Vs Operating System
The kernel is the core of an Operating System. The kernel is a subset but an essential part of
an Operating System.

These are some fundamental differences between Kernel and Operating System.

Section Kernel Operating System

Focus Manages hardware and critical Encompasses utilities, libraries, and


operations interfaces

Loading into Memory Loaded first during system startup The entire system, including the kernel,
is loaded

Responsibilities Core tasks like process scheduling, Includes utilities, libraries, and
resource allocation, etc. interfaces for user interaction

Size Typically smaller in size Larger, incorporating various


components beyond the kernel
Conclusion
The kernel is like the brain of your computer. It manages tasks from handling hardware to
protecting against threats. It bridges your applications and the computer core using calls and
communication. When your computer starts, the kernel is the first in action, handling
memory, disk tasks, and managing processes. It ensures your computer runs smoothly and
also allocates tasks and controls processes.

You might also like