Bca 306 New
Bca 306 New
Bca 306 New
LINUX ENVIRONMENT
UNIT – I
UNIX & LINUX:- Overview of UNIX and LINUX Architectures, UNIX Principles, GNU
Project/FSF,GPL,Getting help in Linux with –help, whatis, man command, info command,
simple commands like date,whoami, who, w, cal, bc ,hostname, name, concept of aliases
etcLinux file system types ext2, ext3, ext4,Basic linux directory structure and the functions of
different directories basic directory navigation commands like cd, mv, copy,rm,cat command ,
less command, runlevel (importance of /etc/inittab)[T1,T2,R1] [No. of Hrs: 11]
UNIT – II
Standard Input and Output, Redirecting input and Output, Using Pipes to connect processes, tee
command, Linux File Security, permission types, examining permissions, changing
permissions(symbolic method numeric method),default permissions and unmask Vi editor
basics, three modes of vi editor, concept of inodes,inodes and directories,cp and inodes ,mv and
inodes rm and inodes, symbolic links and hard links, mount and unmount command, creating
archives, tar,gzip,gunzip,bzip2,bunzip2(basic usage of these commands)[T1,T2,R1]
UNIT – III
UNIT – IV
Process related commands(ps, top, pstree, nice, renice), Introduction to the linux Kernel, getting
started with the kernel(obtaining the kernel source, installing the kernel source,using patches,
the kernel source tree, building the kernel process management(process descriptor and the task
structure, allocating the process descriptor, storing the process descriptor, process state,
manipulating the current process state, process context, the process family tree, the Linux
scheduling algorithm, overview of system calls, Introduction to kernel debuggers(in windows
and linux)[T2]
UNIX has been a popular OS for more than two decades because of its multi-user, multi-tasking
environment, stability, portability and powerful networking capabilities.
In the late 1960s, researchers from General Electric, MIT and Bell Labs launched a joint project
to develop an ambitious multi-user, multi-tasking OS for mainframe computers known as
MULTICS (Multiplexed Information and Computing System). MULTICS failed (for some
MULTICS enthusiasts "failed" is perhaps too strong a word to use here), but it did inspire Ken
Thompson, who was a researcher at Bell Labs, to have a go at writing a simpler operating
system himself. He wrote a simpler version of MULTICS on a PDP7 in assembler and called his
attempt UNICS (Uniplexed Information and Computing System). Because memory and CPU
power were at a premium in those days, UNICS (eventually shortened to UNIX) used short
commands to minimize the space needed to store them and the time needed to decode them -
hence the tradition of short UNIX commands we use today, e.g. ls, cp, rm, mv etc. Ken
Thompson then teamed up with Dennis Ritchie, the author of the first C compiler in 1973. They
rewrote the UNIX kernel in C - this was a big step forwards in terms of the system's portability -
and released the Fifth Edition of UNIX to universities in 1974. The Seventh Edition, released in
1978, marked a split in UNIX development into two main branches: SYSV (System 5) and BSD
(Berkeley Software Distribution). BSD arose from the University of California at Berkeley
where Ken Thompson spent a sabbatical year. Its development was continued by students at
Berkeley and other research institutions. SYSV was developed by AT&T and other commercial
companies. UNIX flavors based on SYSV have traditionally been more conservative, but better
Linux Architecture
• Kernel:The Linux kernel includes device driver support for a large number of PC
hardware devices (graphics cards, network cards, hard disks etc.), advanced processor and
memory management features, and support for many different types of file systems
(including DOS floppies and the ISO9660 standard for CDROMs). In terms of the services
that it provides to application programs and system utilities, the kernel implements most
BSD and SYSV system calls, as well as the system calls described in the POSIX.1
specification.
The kernel (in raw binary form that is loaded directly into memory at system startup time)
is typically found in the file /boot/vmlinuz, while the source files can usually be found in
/usr/src/linux.The latest version of the Linux kernel sources can be downloaded
from http://www.kernel.org.
• Shells and GUIs :Linux supports two forms of command input: through textual
command line shells similar to those found on most UNIX systems (e.g. sh - the Bourne shell,
bash - the Bourne again shell and csh - the C shell) and through graphical interfaces (GUIs)
such as the KDE and GNOME window managers. If you are connecting remotely to a server
your access will typically be through a command line shell.
• System Utilities: Virtually every system utility that you would expect to find on
standard implementations of UNIX (including every system utility described in the POSIX.2
specification) has been ported to Linux. This includes commands such as ls, cp, grep, awk, sed,
bc, wc, more, and so on. These system utilities are designed to be powerful tools that do a single
task extremely well (e.g. grep finds text inside files while wc counts the number of words, lines
and bytes inside a file). Users can often solve problems by interconnecting these tools instead of
writing a large monolithic application program.
UNIX PRINCIPLES
Computer Terms
The Kernel
In Unix (often spelt UNIX), the basic software controlling the hardware is know as the Kernel.
The Kernel does all the difficult and nasty things like managing all the running processes (a
name for a running program), the memory, the network connections, disks, tapes and virtually
any bit of hardware on the computer.
Shells
A shell is a program which allows you to run other programs. Microsoft Windows has a shell
called Explorer which allows you to run programs by clicking on them. Although there are
graphical shells for UNIX, such as Gnome and KDE, they are not installed on the computing
cluster.
Files
In UNIX, like in many environments, data are stored in things called files. A file contains data
made up of a particular number of bytes. Many files in Unix are stored as text; often data in a
program are translated into text for saving and loading. Other files, such as those your programs
could write, or programs themselves, are encoded such that you can load them back into
memory. Files have particular names, which can be hundreds of characters long, and are case
sensitive, so that the file `Hello.txt' isn't the same as the file `hello.txt'. Conventionally files of a
particular type have the same `suffix' or `extension', which is the bit at the end back to the dot.
Directories
Files are stored on disk (which may be a CDROM or a pretend disk in memory, like the /tmp
file system). Files are organized in a `File System Hierarchy' or `Directory Tree' (it looks like a
tree), which sounds a bit complex. A directory is a set of files with a name, which can also
contain other directories. All the directories can be traced back to the root directory, `/'.
The Network File System (NFS) allows you to access your files on different computers.
Names of files are built up from the current working directory, or from root if an absolute name
is given (starting with /). Directories are specified with slashes after them.
Permissions
Processes
When you run a program, you load it into memory and it starts running as a `process'. Processes
compete for the CPU time on the computer , according to their priority or `niceness'. Each
process gets its own identification number (PID), which are recycled eventually. Processes are
identified by this number in the `top' and `ps' process examination tools, and can be used to kill
or stop the process with the `kill' command.
X is a system for displaying graphical applications on Unix (and other) systems. An X server
runs on your computer, and receives requests to open windows, draw windows, accept input,
and so on from a client application (which is the program you are running).
GNU PROJECT/FSF
GNU was launched by Richard Stallman (rms) in 1983, as an operating system which would be
put together by people working together for the freedom of all software users to control their
computing. rms remains the Chief GNUisance today. The primary and continuing goal of GNU
is to offer a Unix-compatible system that would be 100% free software. Not 95% free, not
99.5%, but 100%. The name of the system, GNU, is a recursive acronym meaning GNU's Not
Unix—a way of paying tribute to the technical ideas of Unix, while at the same time saying that
GNU is something different. Technically, GNU is like Unix. But unlike Unix, GNU gives its
users freedom. The GNU packages have been designed to work together so we could have a
functioning GNU system. It has turned out that they also serve as a common “upstream” for
many distros, so contributions to GNU packages help the free software community as a whole.
Naturally, work on GNU is ongoing, with the goal to create a system that gives the greatest
freedom to computer users. GNU packages include user-oriented applications, utilities, tools,
libraries, even games—all the programs that an operating system can usefully offer to its users.
GPL
The GNU General Public License (GNU GPL or GPL) is the most widely used free software
license, which guarantees end users(individuals, organizations, companies) the freedoms to use,
Syntax
Description
Displays brief summaries of shell builtin commands. If PATTERN is specified, gives detailed
help on all commands matching PATTERN; otherwise the list of help topics is printed.
Options
b) whatis,
Syntax: whatis [-dlhvV] [-r|-w] [-s list] [-m system[,...]] [-M path] [-L locale] [-C file] name ...
name may contain wildcards (-w) or be a regular expression (-r). Using these options,
it may be necessary to quote the name or escape (\) the special characters to stop
theshell from interpreting them.
c) man command
On Linux and other Unix-like operating systems, Man is the interface used to view the
system's reference manuals. Man is the system's manual viewer; it can be used to display
manual pages, scroll up and down, search for occurrences of specific text, and other useful
functions. Each argument given to Man is normally the name of a program, utility or function.
The manual page associated with each of these arguments is then found and displayed. A
section number, if provided, will direct Man to look only in that section of the manual.
Syntax
a) man [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-m
system[,...]] [-M
path] [-S list] [-e extension] [-i|---regex|- wildcard] --names-only] [-a] [-u]no-subpages]
I] [ - [ [-- [-
P pager] [-r prompt] [-7] [-E encoding] no-hyphenation] [--no-justification] [-p string] [-
[-- t] [-
T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ...
e) man -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-P pager]
[-r prompt] [-7] [-E encoding] [-p string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z]
file ...
d) info command
Info reads documentation in the info format. Info is similar to man, with a more robust
structure for linking pages together. Info pages are made using the text info tools, and can link
with other pages, create menus and ease navigation in general. The default location of info
documentation is /usr/share/info.
syntax
Info[option]…[Menu-Item]
Options
e) date
About date
Options
-f, --file=DATEFILE like --date, but processed once for each line of file DATEFILE.
f) whoami,
Print effective userid. Would display the name of the current userid. For example, may list
root if you're logged in as root.
Syntax
g) who
About who
Syntax
who [-a] [-b] [-d] [-H] [-l] [-m] [-nx] [-p] [-q] [-r] [-s] [-t] [-T] [-u] [am i] [ file ]
-a Process /var/adm/utmp or the named file with -b, -d, -l, -p, -r, -t, -T, and -u options
turned on.
-d Display all processes that have expired and not been respawned by init . The exit field
appears for dead processes and contains the termination and exit values (as returned by
wait), of the dead process. This can be useful in determining why a process terminated.
-n Take a numeric argument, x, which specifies the number of users to display per line. x must
be at least x 1. The -n option may only be used with -q.
h) W
About w
Displays information about the users currently on the machine, and their processes. The
header shows, in this order, the current time, how long the system has been running, how
many users are currently logged on, and the system load averages for the past 1, 5, and 15
Syntax
w [-husfVo] [user]
Ignores the username while figuring out the current process and cpu times. To
-u demonstrate this,
do a "su" and do a "w" and a "w -u".
-s Use the short format. Don't print the login time, JCPU or PCPU times.
Toggle printing the from (remote hostname) field. The default as released is for the from
f field to
not be printed, although your system administrator or distribution maintainer may
have
compiled a version in which the from field is shown by default.
-o Old style output. Prints blank space for idle times less than one minute.
i) Cal
About cal
cal originally appeared in version 6 of AT&T Unix. Since then there have been versions
released for BSD, Linux, and other Unix variants. You should check your particular
installation's manual for version-specific options. Listed below are the traditional syntax and
options for Unix cal.
In general, if no options are given, cal displays the current month at the command line. It's a
quick and convenient way to glance at the dates of the month, and can be useful as part of a
login script.
Syntax
Options
-3 Display three months: last month, this month, and next month.
-s Display the calendar using Sunday as the first day of the week.
j) bc
About bc
It has an interactive mode, accepting input from the terminal and providing calculations on
request. As a language, its syntax is similar to the C programming language. A standard
math library is available using a command line option. If requested, the math library is
defined before processing any files. bc starts by processing code from all the files listed on
the command line in the order listed. After all files have been processed, bc reads from the
standard input. All code is executed as it is read. Newer versions of bc contain several
extensions beyond traditional bc implementations and the POSIX draft standard.
Command-line options can cause these extensions to print a warning or to be rejected. This
document describes the newer version of the bc language
Syntax
Options
-v, --version Print the version number and copyright information, and exit.
About hostname
Syntax
Description
hostname is used to display the system's DNS name, and to display or set its hostname or
NIS (Network Information Services) domain name.
When called without any arguments, hostname will display the name of the system as
returned by the gethostname function.
When called with one argument or with the --file option, hostname will set the system's
host name using the sethostname function. (Only the superuser can set the host name.)
The host name is usually set once at system startup in the script/etc/init.d/hostname.sh
(normally by reading the contents of a file which contains the host name, e.g.
/etc/hostname).
Options
Displays all FQDNs of the machine. This option enumerates all configured
-A, --all-fqdns network
addresses on all configured network interfaces, and translates them to DNS
domain
names. Addresses that cannot be translated (i.e. because they do not have
an
appropriate reverse DNS entry) are skipped. Note that different addresses may
resolve
to the same name, therefore the output may contain duplicate entries. Do not
make
any assumptions about the order of the output.
-b, --boot Always set a hostname; this allows the file specified by -F to be non-existant or
empty, in which case the default hostname localhost will be used if none is yet
set.
Display the name of the DNS domain. Don't use the command domainname to
-d, --domain get
the DNS domain name because it will show the NIS domain name and not the
DNS
domain name. Use dnsdomainname instead. See the warnings in section The
FQDN,
and avoid using this option if at all possible.
l) uname
About uname
Syntax
uname [-a] [-i] [-m] [-n] [-p] [-r] [-s] [-v] [-X] [-S systemname]
Print the machine hardware name (class). Use of this option is discouraged;
-m use
uname -p instead.
Print the nodename (the nodename is the name by which the system is
-n known to a
communications network).
m) concept of aliases
About alias
alias instructs the shell to replace one string with another when executingcommands. It is used
to customize the shell session interface. Using alias, frequently-used commands can be
invoked using a different, preferred term; and complex or commonly-used options can be used
as the defaults for a given command.
Aliases persist for the current session. They can be loaded at login time by modifying the
shell's .rc file. The invocation and usage of alias differs depending on the shell; see your
shell's documentation for details.
Syntax
alias [name=['command']]
Ext2
This was developed to overcome the limitation of the original ext file
system. Ext2 does not have journaling feature.
On flash drives, usb drives, ext2 is recommended, as it doesn’t need to do the over
head of journaling.
Ext3
Journaling has a dedicated area in the file system, where all the changes are tracked. When
the system crashes, the possibility of file system corruption is less because of journaling.
Ordered – Only metadata is saved in the journal. Metadata are journaled only after
writing the content to disk. This is the default.
You can convert a ext2 file system to ext3 file system directly (without backup/restore).
Ext4
Several other new features are introduced in ext4: multiblock allocation, delayed allocation,
journal checksum. fast fsck, etc. All you need to know is that these new features have
improved the performance and reliability of the filesystem when compared to ext3.
In ext4, you also have the option of turning the journaling feature “off”.
Several major directories are associated with all modern Unix/Linux operating systems. These
directories organize user files, drivers, kernels, logs, programs, utilities, and more into different
categories. The standardization of the FHS makes it easier for users of other Unix-based
operating systems to understand the basics of Linux. Every FHS starts with the root directory,
also known by its label, the single forward slash (/). All of the other directories shown in Table
are subdirectories of the root directory. Unless they are mounted separately, you can also find
their files on the same partition as the root directory.
The root directory, the top-level directory in the FHS. All other directories are
subdirectories of root, which is always mounted on some partition. All
/
directories that are not mounted on a separate partition are included in the root directory?s
partition.
as for testing a kernel upgrade, increase the size of this partition accordingly.
Program libraries for the kernel and various command line utilities. Do
not
/lib
mount this directory on a separate partition.
The mount point for removable media, including floppy drives, CD-
ROMs, and
/mnt
Zip disks.
Temporary files. By default, Red Hat Linux deletes all files in this
directory
/tmp
periodically.
Syntax
Description
dirname outputs each NAME with its last non-slash component and trailing slashes
removed; if NAME contains no /'s, dirname outputs a single '.' (meaning the current
directory).
-z, --zero separate output with NUL rather than a newline.
a) cd
About cd
Syntax
cd [-L|-P] directory
Options
b) Mv
About mv
Syntax
mv -t DIRECTORY
[OPTION]... SOURCE...
mv renames file SOURCE to DEST, or moves the SOURCE file (or files) to DIRECTORY.
Options
Like --backup, but does not accept an argument; the default backup
-b method
is used.
If you specify more than one of the obove options -i, -f, or -n, only the final option specified
takes effect.
Use the suffix SUFFIX for all backup files. The default
-S, --suffix=SUFFIX SUFFIX is
"~".
-u, --update Perform the move only if the SOURCE file is newer than the
destination file, or the destination file does not already exist.
c) Cp
About cp
Syntax
cp -t DIRECTORY
[OPTION]... SOURCE...
Options
don't copy the file data, just create a file with the same
--attributes-only attributes.
-i, --
interactive prompt before overwrite (overrides a previous -n option).
About rm
Syntax
-R Same as -r option.
About cat
cat stands for "catenate." It reads data from files, and outputs their contents. It is the simplest
way to display the contents of a file at the command line.
Syntax
-e equivalent to -vE
-t equivalent to -vT
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
f) less command
About less
Syntax
Description
less is a program similar to more, but it has many more features. less does not have to read the
entire input
file before starting, so with large input files it starts up faster than text editors
like vi. less uses termcap (or terminfo on some systems), so it can run on a variety of terminals.
There is
even limited support for hardcopy terminals. On a hardcopy terminal, lines which should be
printed at the
Commands are based on both more and vi. Commands may be preceded by a decimalnumber,
called N in
Commands
COPYRIGHT FIMT 2021 Page 29
In the following descriptions, ^X means control-X. ESC stands for the ESCAPE key; for
example ESC-
Like scroll
ESC-SPACE SPACE, but s a full screenful, even if it
reaches end-of-file in the process.
Like ESC-v,
W but if N is specified, it becomes the new
window size.
g) Runlevels
A runlevel is a software configuration of the system which allows only a selected group of
processes to exist. The processes spawned by init for each of these runlevels are
defined in the /etc/inittab file. Init can be in one of eight runlevels: 0 through 6, andS or s.
UNIT-II
STANDARD INPUT
Standard input, often abbreviated stdin, is the input data for a program in the absence of any
command line arguments. It is by default any text entered from the keyboard. Thus if wc is typed
in at the command line and the ENTER key is pressed without providing any arguments, any text
typed in on all subsequent lines will be stored in memory until the wc command is executed by
simultaneously pressing the CONTROL and d keys on a new, blank line. wc will then count the
lines, words and characters in that stored text.Standard input can be redirected to come from any
text file in place of the keyboard by using the input redirection operator, which is a leftward
pointing angular bracket. Thus, to redirect the standard input for the command sort (which sorts
lines of text in alphabetic order) from the keyboard to the file named file3, type:
The result is the same as using file3 as an argument, although the mechanism is different, i.e.,
sort file3
STANDARD OUTPUT
Most command line programs that display their results do so by sending their results to a facility
called standard output. By default, standard output directs its contents to the display. To redirect
standard output to a file, the ">" character is used like this:
In this example, the ls command is executed and the results are written in a file named
file_list.txt. Since the output of lswas redirected to the file, no results appear on the display.
When the results are appended, the new results are added to the end of the file, thus making the
file longer each time the command is repeated. If the file does not exist when you attempt to
append the redirected output, the file will be created.Many commands can accept input from a
facility called standard input. By default, standard input gets its contents from the keyboard, but
like standard output, it can be redirected. To redirect standard input from a file instead of the
keyboard, the "<" character is used like this:
In the above example we used the sort command to process the contents of file_list.txt. The
results are output on the display since the standard output is not redirected in this example. We
could redirect standard output to another file like this:
As you can see, a command can have both its input and output redirected. Be aware that the
order of the redirection does not matter. The only requirement is that the redirection operators
(the "<" and ">") must appear after the other options and arguments in the command.
the most useful and powerful thing you can do with I/O redirection is to connect multiple
commands together with what are called pipes. With pipes, the standard output of one command
is fed into the standard input of another. Here is my absolute favorite:
In this example, the output of the ls command is fed into less. By using this "| less" trick, you
can make any command have scrolling output. I use this technique all the time.
By connecting commands together, you can acomplish amazing feats. Here are some examples
Command
ls -lt | head
du | sort –nr
About tee
What it does
Displays a list of directories and how much space they consume, sorted from the
largest to the smallest.
Displays the total number of files in the current working directory and all of its
subdirectories.
Syntax
The Linux security model is based on the one used on UNIX systems, and is as rigid as the
UNIX security model (and sometimes even more), which is already quite robust. On a
Linux system, every file is owned by a user and a group user. There is also a third category
of users, those that are not the user owner and don't belong to the group owning the file.
For each category of users, read, write and execute permissions can be granted or denied.
We already used the long option to list files using the ls -l command, though for other
reasons. This command also displays file permissions for these three user categories; they
are indicated by the nine characters that follow the first character, which is the file type
indicator at the beginning of the file properties line. As seen in the examples below, the
first three characters in this series of nine display access rights for the actual user that owns
the file. The next three are for the group owner of the file, the last three for other users. The
permissions are always in the same order: read, write, execute for the user, the group and
the others.
Permission Groups
Each file and directory has three user based permission groups:
• owner - The Owner permissions apply only the owner of the file or directory, they will not
impact the actions of other users.
• group - The Group permissions apply only to the group that has been assigned to the file
or directory, they will not effect the actions of other users.
• all users - The All Users permissions apply to all other users on the system, this is the
permission group that you want to watch the most.
PERMISSION TYPES
• read - The Read permission refers to a user's capability to read the contents of the file.
• write - The Write permissions refer to a user's capability to write or modify a file or
directory.
• execute - The Execute permission affects a user's capability to execute a file or view the
contents of a directory.
You can view the permissions by checking the file or directory permissions in your favorite
GUI File
Manager (which I will not cover here) or by reviewing the output of the \"ls -l\" command
while in the terminal and while working in the directory which contains the file or folder.
1. User rights/Permissions
1. The first character that I marked with an underscore is the special permission flag that
can vary.
2. The following set of three characters (rwx) is for the owner permissions.
4. The third set of three characters (rwx) is for the All Users permissions.
2. Following that grouping since the integer/number displays the number of hardlinks to the
file.
3. The last piece is the Owner and Group assignment formatted as Owner:Group.
When in the command line, the permissions are edited by using the command chmod. You
can assign the permissions explicitly or by using a binary reference as described below.
To explicity define permissions you will need to reference the Permission Group and
Permission Types.
• u - Owner
• g - Group
• o or a - All Users
The potential Assignment Operators are + (plus) and - (minus); these are used to tell the
system whether to add or remove the specific permissions.
• r - Read
• w - Write
• x - Execute
h) permission types:
There are two parts to permissions. The first involves what someone is allowed to do with a
When controlling what can be done to a file or directory, there are three categories of actions:
read, write, and execute. What is specifically allowed or disallowed can be different for files
and directories, so we’ll talk about both for each category.
Read
The “read” permission controls, well, who can read a file. If you don’t have read
permissions for a file you can’t look inside and see its contents. The “read” permission for a
directory controls whether or not you can see a list of the files in the directory. Note,
however, that to do so you will also need “execute” permission for the directory.
Write
The “write” permission on a file controls whether or not you can change the file’s contents. If
you want to edit the text in an html file, for example, you need write permission before you can
do so. The “write” permission on a directory controls whether or not you can add, delete, or
rename files in that directory.
Execute
The “execute” permission for a file allows you to run that file from the command line. In order
to run any command (“chown”, “ls”, “rm”, etc.), you have to have execute permission for the
file representing that command. If you try to run a command and get a “permission denied”
error, it’s because you don’t have execute permission. The “execute” permission for a
directory lets you perform an operation in that directory, or to change your working directory
(“cd”) to that directory.
i) EXAMINING PERMISSIONS
By examining permissions for each of the following files, identify if it is a file or directory,
and describe the access allowed to the world, user, and group:
• a. -rwx---r-x
• c. -rwxrwxr--
• d. dr-x---r-x
• e. -rwx---rwx
In order to change the permissions of a file using symbolic permissions, use the command
format:
The letters for user, group, and other are u,g, and o respectively. The letter a is used to mean
all three of these categories.
To set the permissions of a file or directory using numeric modes, simply use the format:
For example, to set the permissions of filename to -rw-r--r-- you could run the command:
Be careful when setting permissions to 777 as this means every single user account can
When a user creates a file, how does the system determine that file's initial permissions? This
is done based on the user's umask value. The umask value specifies which permissions are not
to be set. In Ubuntu, the default umask value for a normal user is 002, while the default for
root is 022. You can find out the current umask value (or set it) using the umask command. If
(as a normal user) you run the command:
umask
EDITOR BASICS
There are many ways to edit files in Unix and for me one of the best ways is using screen-
oriented text editor vi. This editor enable you to edit lines in context with other lines in the
file. Now a days you would find an improved version of vi editor which is called VIM.
Here VIM stands for ViIMproved.
Command Description
The vi editor has three modes, command mode, insert mode and command line mode.
Command mode: letters or sequence of letters interactively command vi. Commands are
case sensitive. The ESC key can end a command.
Insert mode: Text is inserted. The ESC key ends insert mode and returns you to
command mode. One can enter insert mode with the "i" (insert), "a" (insert after), "A"
(insert at end of line), "o" (open new line after current line) or "O" (Open line above
current line) commands.
Command line mode: One enters this mode by typing ":" which puts the command line
entry at the foot of the screen.
CONCEPT OF INODES,
The inode (index node) is a fundamental concept in the Linux and UNIX filesystem. Each
object in the filesystem is represented by an inode. But what are the objects? Let us try to
understand it in simple words. Each and every file under Linux (and UNIX) has following
attributes:
=>
Owner
=> Group
=> File
Size
=> File access, change and modification time (remember UNIX or Linux never stores file
creation time, this is favorite question asked in UNIX/Linux sys admin job interview)
=> Extended attribute such as append only or no one can delete file including root
user (immutability)
inode definition
An inode is a data structure on a traditional Unix-style file system such as UFS or ext3. An
inode stores basic information about a regular file, directory, or other file system object.
Example:$ ls -i /etc/passwd
Inode Basics
An Inode number points to an Inode. An Inode is a data structure that stores the
following information about a file :
Size of
file
Device
ID
The file mode information and access privileges for owner, group and
others File protection flags
The timestamps for file creation, modification etc link counter to determine the number of hard
links Pointers to the blocks storing file’s contents
Directory in linux
Linux stores data and programs in files. These are organized in directories. In a simple way, a
directory is just a file that contains other files (or directories).
echo $HOME
There is a general directory called /tmp where every user can write files. But files in /tmp
usually get removed (erased) when the system boots or periodically, so you should not store
in /tmp data that you want to keep permanently.
mkdir directory-name
cd directory-name
This assumes that the new directory is a subdirectory of the one you are currently
working on. If that is not the case, you will have to type the name, for example:
cd /usr/local/share/bin
Renaming directories
mv directory-name new-name
About cp
Syntax
Description
About mv
Description
mv renames file SOURCE to DEST, or moves the SOURCE file (or files) to
DIRECTORY.
About rm
Syntax
rm [OPTION]... FILE...
Description
The removal process unlinks a filename in a filesystem from data on the storage device,
and marks that space as usable by future writes. In other words, removing files increases
the amount of available space on your disk.
In a file system, inodes consist roughly of 1% of the total disk space, whether it is a whole
storage unit (hard disk,thumb drive, etc.) or a partition on a storage unit. The inode space is
used to “track” the files stored on the hard disk. The inode entries store metadata about each
file, directory or object, but only points to these structures rather than storing the data. Each
entry is 128 bytes in size. The metadata contained about each structure can include the
following:
• Inode number
• Extended attribute
• Number of blocks
• File size
• File type
• Group
• Number of links
• Owner
• Permissions
• Status flags
Soft link or symlink, a symbolic link is a Linux and Unixfile created with the ln command
that links to another file using the path. Unlike a hard link, a symbolic link can link to any
file on any computer. If you're more familiar with Microsoft Windows you can think of a
symbolic link as a shortcut in Linux.
A hard link is a link file created with the Linux or Unix ln command that points to a file's
inode.
mount [-lhV]
umount [-hV]
CREATING ARCHIVES
Substitute the name.tar with the name of the tar file you would like to create and
substitute the directory name for the full path to the directory you would like to archive.
• To create an archive of certfain files you would type the following and press enter:
Substitute the name.tar with the name of the tar file you would like to create and substitute
the the various files for the full path to the files you would like to archive. Each file you
would like included in the archive should be seperated by a space.
About tar
The tar program is used to create, modify, and access file archives of the tar format.
Syntax
--tar[-]A --catenateconcatenate | c --create | d -- --diff
compare | --delete | r --append | t -- list | --test-label | u --
update | x --extract --get [options] [pathname ... ]
Description
tar was originally developed in the early days of Unix for the purpose of backing up
files to tape-based storage devices. It was later formalized as part of the POSIXstandard,
and today is used to collect, distribute, and archive files, while preservingfile system
attributes such as user and group permissions, access and modification dates, and
directory structures.
GZIP,
gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible,
each file is replaced by one with the extension .gz, while keeping the sameownership modes,
access and modification times. (The default extension is - gz forVMS, z for MSDOS, OS/2
FAT, Windows NT FAT and Atari.) If no files are specified, or if a file name is "-", the
standard input is compressed to the standard output. gzip will only attempt to compress regular
files. In particular, it will ignore symbolic links.
GUNZIP
the .tgz extension if necessary instead of truncating a file with a .tar extension.
BZIP2
bzip2 expects a list of file names to accompany the command-line flags. Each file is replaced
by a compressed version of itself, with the name "original_name.bz2". Each compressed file
has the same modification date, permissions, and, when possible, ownership as the
corresponding original, so that these properties can be correctly restored at decompression
time. File name handling is naive in the sense that there is no mechanism for preserving
original file names, permissions, ownerships or dates in filesystems which lack these concepts,
or have serious file name length restrictions, such as MS-DOS.
bunzip2 (or bzip2 -d) decompresses all specified files. Files which were not created by
bzip2 will be detected and ignored, and a warning issued. bzip2 attempts to guess the
filename for the decompressed file from that of the compressed file as follows:
ENVIRONMENT VARIABLES
An environment variable is a named object that contains data used by one or more
applications. In simple terms, it is a variable with a name and a value. The value of an
environmental variable can for example be the location of all executable files in the file
system, the default editor that should be used, or the system locale settings. Users new to
Linux may often find this way of managing settings a bit unmanageable. However, an
environment variable provides a simple way to share configuration settings between multiple
applications and processes in Linux.
HOME Contains the path to the home directory of the current user. This variable can be used
by applications to associate configuration files and such like with the user running it.
SHELL Contains the name of the running, interactive shell, i.e bash
VISUAL Contains the path to full-fledged editor that is used for more demanding tasks,
such as editing mail; e.g., vi, vim, emacs, etc.
BROWSER Contains the path to the web browser. Helpful to set in an interactive shell
configuration file so that it may be dynamically altered depending on the availability of a
graphic environment, such as X
LANG contain the setting for every categories that are not directly set by a LC_* variable.
LC_ALL is used to override every LC_* and LANG and LANGUAGE, it should not be
set in a normal user environment, but can be useful when you are writing a script that
depend on the precise output of a internationalized command.
USEWR This variable should have the same setting and purpose as LOGNAME(The name
of the user. This is an easy way for a user to get own username. However, programs must
not trust this variable because it can be set to an arbitrary value.
Examples:
LOGNAME=tux
LOGNAME=sudhir
LOCAL VARIABLES
• This can be result into problem. For example, create a shell script
called fvar.sh: Commands :
local var=value
local varName
CONCEPT OF /ETC/PASSWD
The /etc/passwd contains one entry per line for each user (or user account) of the system.
All fields are separated by a colon (:) symbol. Total seven fields as follows.
1. Username: It is used when user logs in. It should be between 1 and 32 characters in length.
5. User ID Info: The comment field. It allow you to add extra information about the users
such as user's full name, phone number etc. This field use by finger command.
6. Home directory: The absolute path to the directory the user will be in when they
log in. If this directory does not exists then users directory becomes /
/ETC/SHADOW
A. /etc/shadow file stores actual password in encrypted format for user's account with
additional properties related to user password i.e. it stores secure user account information.
All fields are separated by a colon (:) symbol. It contains one entry per line for each user
listed in /etc/passwd file Generally, shadow file entry looks as follows (click to enlarge
image):
3. Last password change (last changed): Days since Jan 1, 1970 that password was last
changed
4. Minimum: The minimum number of days required between password changes i.e. the
number of days left before the user is allowed to change his/her password
5. Maximum: The maximum number of days the password is valid (after that user is
forced to change his/her password)
6. Warn : The number of days before password is to expire that user is warned that
7. Inactive : The number of days after password expires that account is disabled
8. Expire : days since Jan 1, 1970 that account is disabled i.e. an absolute date specifying
when the login may no longer be used
/ETC/GROUP
/etc/group is a text file which defines the groups to which users belong under Linux and
UNIX operating system. Under Unix / Linux multiple users can be categorized into groups.
Unix file system permissions are organized into three classes, user, group, and others. The
use of groups allows additional abilities to be delegated in an organized fashion, such as
access to disks, printers, and other peripherals.
This method, amongst others, also enables the Superuser to delegate some administrative
tasks to normal users.It stores group information or defines the user groups i.e. it defines the
groups to which users belong. There is one entry per line, and each line has the following
format (all fields are separated by a colon (:)
cdrom:x:24:vivek,student13,raj
_____ _ _ _____
| || |
| || |
1 23 4
Where,
1. group_name: It is the name of group. If you run ls -l command, you will see this name
printed in the group field.
2. Password: Generally password is not used, hence it is empty/blank. It can store encrypted
password. This is useful to implement privileged groups.
4. Group List: It is a list of user names of users who are members of the group. The user
names, must be separated by commas.
SU- COMMAND
The su (short for substitute user) command makes it possible to change a login session's owner
(i.e., the user who originally created that session by logging on to the system) without the
owner having to first log out of that session. Although su can be used to change the ownership
of a session to any user, it is most commonly employed to change the ownership from an
ordinary user to the root(i.e., administrative) user, thereby providing access to all parts of and
all commands on the computer or system. For this reason, it is often referred to (although
somewhat inaccurately) as the super user command. It is also sometimes called the switch user
command.
When a SUID bit is set on a command then that command always executes with the User
ID of its own user owner (who created it) instead of the user who is executing
it.EXAMPLE: The binary
of passwd command has SUID permission set on it, that is why, when unpriviledged users
execute this command, it always executes with the UID of "root" and changes their password
in /etc/shadow (which is only readable or writable by root).
When SGID permission is set on any command, then that command runs with the Group ID of
When SGID permission is set on a directory, then all the new (future) files created under
that directory will have the same group owner as that of the parent directory. Moreover
subdirectories (created in future) will also have SGID bit on them. Example: If we set SGID
on a directory, for example:
on /tmp/test with group owner as "john", now if another user "mike" creates any file in
/tmp/test directory then the user owner of this file will be "mike" but group owner will be
"john" because of SGID on parent directory. To set SGID on a directory, run:
STICKY BIT
The new files created under the directory having Sticky Bit on it can be only deleted by root
or the user who created that file. No other user can delete that file even if they have write
permission on the parent directory. EXAMPLE: /tmp directory is having Sticky Bit
permission on it, that is why the content under this can be only deleted by root or the user
owner of the content/file. To set Sticky Bit on a directory, run:
TAIL
command
DESCRIPTION
--retry :>keep trying to open a file even if it is inaccessible when tail starts or if it becomes
inaccessible later -- useful only with -f-c, --bytes=N:>output the last N bytes
-s, --sleep-interval=S:>with -f, sleep for approximately S seconds (default 1.0) between
iterations. -v, --verbose:>always output headers giving file names
--help:>display t
WC
Short for word count, wc displays a count of lines, words, and characters in a file.
Syntax
-c Count bytes.
-m Count characters.
-C Same as -m.
COPYRIGHT FIMT 2021 Page 57
-l Count lines.
SORT
About sort
Syntax
-f Ignores caps
-M Treats the first three letters in the line as a month (such as may.)
UNIQ
About uniq
Syntax
-c Precede each output line with a count of the number of times the line occurred in the
input.
-f fields Ignore the first fields fields on each input line when doing comparisons, where
fields is a positive decimal integer. A field is the maximal string matched by
the
basic regular expression:
[[:blank:]]*[^[:blank:]]*
If fields specifies more fields than appear on an input line, a null string will be
used
for comparison.
Ignore the first chars characters when doing comparisons, where chars is a
-s char positive
decimal integer. If specified in conjunction with the -f option, the first
chars
characters after the first fields fields will be ignored. If chars specifies
more
characters than remain on an input line, a null string will be used for
comparison.
CUT
About cut
Syntax
-d, --delimiter=DELIM use DELIM instead of a tab for the field delimiter
TR
About
tr
Syntax
In this form, the characters in the string string1 are translated into the characters instring2
where the first character in string1 is translated into the first character instring2 and so on.
DIFF
About diff
Displays two files and prints the lines that are different.
Syntax
Options
aspell is an interactive spell checker. It will scan your files (or anything from standard input),
check for
Syntax
Commands
usage, -? Send a brief Aspell Utility usage message to standard output. This
is a short summary listing more common spell-check
commands and options.
About grep
Syntax
Description
grep searches the named input FILEs (or standard input if no files are named, or if a single
dash ("-") is given as the file name) for lines containing a match to the given PATTERN. By
default, grep prints the matching lines.
In addition, three variant programs egrep, fgrep and rgrep are available:
Direct invocation as either egrep or fgrep is deprecated, but is provided to allow historical
applications that rely on them to run unmodified.
General Options
SED
Sort for Stream Editor sed allows you to use pre-recorded commands to make changes to text.
Syntax
script is an edit command for sed . See USAGE below for more information on the
-e script format of
script. If there is just one -e option and no -f options, the flag -e may be omitted.
-f Take the script from script_file. script_file consists of editing commands, one per line.
script_file
A path name of a file whose contents will be read and edited. If multiple file operands
File are
specified, the named files will be read in the order specified and the concatenation will
be
edited. If no file operands are specified, the standard input will be used
AWK(BASIC USAGE)
AWK was developed in the 1970s at Bell Labs by Alfred Aho, Peter Weinberger, andBrian
Kernighan. It was designed to execute complex pattern-matching operations on streams of
textual data. It makes heavy use of strings, associative arrays, and regular expressions, and
is immensely useful for parsing system data and generating automatic reports.
AWK is a direct predecessor of Perl, and is still very useful in modern systems.
TheGNU free software project distributes an open-source version of AWK called gawk.
Syntax
Arguments
-F fs Sets the input field separator to the regular expression fs.
Assigns the value value to the variable var before executing the awk
-v var=value program.
-f progfile Specify a file, progfile, which contains the awk program to be executed.
The Linux terminal has a number of useful commands that can display running processes, kill
them, and change their priority level. This post lists the classic, traditional commands, as well
as some more useful, modern ones. Many of the commands here perform a single function and
can be combined — that’s the Unix philosophy of designing programs. Other programs, like
htop, provide a friendly interface on top of the commands.
Top
The top command is the traditional way to view your system’s resource usage and see the
processes that are taking up the most system resources. Top displays a list of processes,
with the ones using the most CPU at the top.
ps
The ps command lists running processes. This may be too many processes to read at one time, so
you can pipe the output through the less command to scroll through them at your own pace:
Press q to exit when you’re done. The following command lists all processes running on your
system:
ps -A
pstree
The pstree command is another way of visualizing processes. It displays them in tree format. So,
for example, your X server and graphical environment would appear under the display manager
that spawned them.
kill
The kill command can kill a process, given its process ID. You can get this information from the
ps - A, top or pgrep commands. Technically speaking, the kill command can send any signal to
a process. You can use kill -KILL or kill -9 instead to kill a stubborn process
kill PID
renice
The renice command changes the nice value of an already running process. The nice value
renice 19 PID
A kernel is the core of an operating system. The operating system is all of the programs that
manages the hardware and allows users to run applications on a computer. The kernel controls
the hardware and applications. Applications do not communicate with the hardware directly;
instead they go to the kernel.
In summary, software runs on the kernel and the kernel operates the hardware. Without a kernel,
a computer is a useless object.
There are many reasons for a user to want to make their own kernel. Many users may want to
make a kernel that only contains the code needed to run on their system. For instance, my kernel
contains drivers for FireWire devices, but my computer lacks these ports. When the system boots
up, time and RAM space is wasted on drivers for devices that my system does not have installed.
If I wanted to streamline my kernel, I could make my own kernel that does not have FireWire
drivers. As for another reason, a user may own a device with a special piece of hardware, but the
kernel that came with their latest version of Ubuntu lacks the needed driver. The Linux kernel is
also a preemptive multitasking kernel. This means that the kernel will pause some tasks to ensure
that every application gets a chance to use the CPU. For instance, if an application is running but
is waiting for some data, the kernel will put that application on hold and allow another program
to use the newly freed CPU resources until the data arrives. Otherwise, the system would be
wasting resources for tasks that are waiting for data or another program to execute.
The kernel will force programs to wait for the CPU or stop using the CPU. The Linux kernel
makes devices appear as files in the folder /dev. USB ports, for instance, are located in
/dev/bus/usb. The hard-drive partitions are seen in /dev/disk/by-label.
All of the major Linux distributions ( Craftworks, Debian, Slackware, Red Hat etcetera) include
the kernel sources in them. Usually the Linux kernel that got installed on your Linux system was
built from those sources. They are kept onftp://ftp.cs.helsinki.fi and all of the other web sites
shadow them. This makes the Helsinki web site the most up to date, but sites like MIT and
Sunsite are never very far behind. If you do not have access to the web, there are many CD ROM
vendors who offer snapshots of the world's major web sites at a very reasonable cost. Some even
offer a subscription service with quarterly or even monthly updates. Your local Linux User
Group is also a good source of sources.
The Linux kernel sources have a very simple numbering system. Any even number kernel (for
example 2.0.30) is a stable, released, kernel and any odd numbered kernel (for example 2.1.42 is
Remember that it is always worth backing up your system thoroughly if you do try out non-
production kernels. Changes to the kernel sources are distributed as patch files. The patch utility
is used to apply a series of edits to a set of source files. So, for example, if you have the 2.0.29
kernel source tree and you wanted to move to the 2.0.30 source tree, you would obtain the 2.0.30
patch file and apply the patches (edits) to that source tree:
$ cd /usr/src/linux
"Source tree" is just a term for the directory which contains the source code you will be
compiling.
When a kernel source package is installed, the source tarball is placed in the /usr/src directory.
To work in this directory, you must be the either the root user or a member of the src group. To
avoid doing things as root whenever possible, add yourself to src. Only the root user can add
users to groups, so become root and do the following:
bash:~# adduser my_username src Adding user my_username to group src...
Done.
bash:~$ groups
my_username src
using patches
Copy the patch that you generated in Step 2 to the directory containing the file to which you
want to apply the patch. Now, type in your shell:
patch <patch_file
The kernel source tree is divided into a number of directories, most of which contain many more
subdirectories. The directories in the root of the source tree, along with their descriptions, are
listed
Directory Description
Directory Description
The Process Management subsystem controls the creation, termination, accounting, and
scheduling of processes. It also oversees process state transitions and the switching between
privileged and non-privileged modes of execution. The Process Management subsystem also
facilitates and manages the complex task of the creation of child processes. A simple definition
of a process is that it is an executing program. It is an entity that requires system resources, and it
has a finite lifetime. It has the capability to create other processes via the system call interface. In
short, it is an electronic representation of a user's or programmer's desire to accomplish some
useful piece of work. A process may appear to the user as if it is the only job running in the
machine. This "sleight of hand" is only an illusion. At any one time a processor is only executing
a single process.
The kernel stores the list of processes in a circular doubly linked list called the task list. Each
element in the task list is a process descriptor of the type struct task_struct, which is defined in
<Linux/sched.h>. The process descriptor contains all the information about a specific process.
The task_struct is a relatively large data structure, at around 1.7 kilobytes on a 32-bit machine.
This size, however, is quite small considering that the structure contains all the information that
the kernel has and needs about a process. The process descriptor contains the data that describes
the executing program open files, the process's address space, pending signals, the process's
state, and much more
The task_struct structure is allocated via the slab allocator to provide object reuse and cache
coloring
.Prior to the 2.6 kernel series, struct task_struct was stored at the end of the kernel stack of each
process. This allowed architectures with few registers, such as x86, to calculate the location of
the process descriptor via the stack pointer without using an extra register to store the location.
With the process descriptor now dynamically created via the slab allocator, a new structure,
struct thread_info, was created that again lives at the bottom of the stack (for stacks that grow
down) and at the top of the stack (for stacks that grow up) See Figure . The new structure also
makes it rather easy to calculate offsets of its values for use in assembly code.
The system identifies processes by a unique process identification value or PID. The PID is a
numerical value that is represented by the opaque type pid_t, which is typically an int. Because
of backward compatibility with earlier Unix and Linux versions, however, the default maximum
value is only 32,768 (that of a short int), although the value can optionally be increased to the
full range afforded the type. The kernel stores this value as pid inside each process descriptor.
This maximum value is important because it is essentially the maximum number of processes
that may exist concurrently on the system. Although 32,768 might be sufficient for a desktop
system, large servers may require many more processes. The lower the value, the sooner the
values will wrap around, destroying the useful notion that higher values indicate later run
PROCESS STATE
The state field of the process descriptor describes the current condition of the process Each
process on the system is in exactly one of five different states. This value is represented by one
of five flags:
o TASK_ZOMBIE The task has terminated, but its parent has not yet issued a wait4()
system call. The task's process descriptor must remain in case the parent wants to access
it. If the parent calls wait4(), the process descriptor is deallocated.
o TASK_STOPPED Process execution has stopped; the task is not running nor is it
eligible to run. This occurs if the task receives the SIGSTOP, SIGTSTP, SIGTTIN, or
SIGTTOU signal or if it receives any signal while it is being debugged.
Kernel code often needs to change a process's state. The preferred mechanism is using
This function sets the given task to the given state. If applicable, it also provides a memory
barrier to force ordering on other processors (this is only needed on SMP systems). Otherwise, it
is equivalent to
task->state = state;
The method set_current_state(state) is synonymous to set_task_state(current, state).
PROCESS CONTEXT
One of the most important parts of a process is the executing program code. This code is read in
from an executable file and executed within the program's address space. Normal program
execution occurs in user-space. When a program executes a system call or triggers an exception,
it enters kernel-space. At this point, the kernel is said to be "executing on behalf of the process"
and is in process context. When in process context, the current macro is valid .Upon exiting the
kernel, the process resumes execution in user-space, unless a higher-priority process has become
runnable in the interim, in which case the scheduler is invoked to select the higher priority
process. System calls and exception handlers are well-defined interfaces into the kernel. A
process can begin executing in kernel-space only through one of these interfaces all access to the
kernel is through these interfaces.
A distinct hierarchy exists between processes in UNIX systems, and Linux is no exception. All
processes are descendents of the init process, whose PID is one. The kernel starts init in the last
step of the boot process. The init process, in turn, reads the system init scripts and executes more
programs, eventually completing the boot process.
Every process on the system has exactly one parent. Likewise, every process has zero or more
children. Processes that are all direct children of the same parent are called siblings. The
relationship between processes is stored in the process descriptor. Each task_struct has a pointer
to the parent's task_struct, named parent, and a list of children, named children. Consequently,
given the current process, it is possible to obtain the process descriptor of its parent with the
following code:
The Linux scheduling algorithm works by dividing the CPU time into epochs. In a single epoch,
every process has a specified time quantum whose duration is computed when the epoch begins.
In general, different processes have different time quantum durations. The time quantum value is
the maximum CPU time portion assigned to the process in that epoch. When a process has
exhausted its time quantum, it is preempted and replaced by another runnable process. Of course,
a process can be selected several times from the scheduler in the same epoch, as long as its
quantum has not been exhausted--for instance, if it suspends itself to wait for I/O, it preserves
some of its time quantum and can be selected again during the same epoch. The epoch ends
when all runnable processes have exhausted their quantum; in this case, the scheduler algorithm
recomputes the time-quantum durations of all processes and a new epoch begins.
Each process has a base time quantum: it is the time-quantum value assigned by the scheduler to
the process if it has exhausted its quantum in the previous epoch. The users can change the base
time quantum of their processes by using the nice( ) and setpriority( ) system calls (see the
section "System Calls Related to Scheduling" later in this chapter). A new process always
inherits the base time quantum of its parent.
The INIT_TASK macro sets the value of the base time quantum of process 0 (swapper) to
DEF_PRIORITY; that macro is defined as follows:
Since HZ, which denotes the frequency of timer interrupts, is set to 100 for IBM PCs (see the
section "Programmable Interval Timer" in Chapter 5), the value of DEF_PRIORITY is 20 ticks,
that is, about 210 ms.
Users rarely change the base time quantum of their processes, so DEF_PRIORITY also denotes
the base time quantum of most processes in the system.
In order to select a process to run, the Linux scheduler must consider the priority of each process.
Actually, there are two kinds of priority:
Static priority
This kind is assigned by the users to real-time processes and ranges from 1 to 99. It is
never changed by the scheduler.
Dynamic priority
Before trying to debug the kernel, we must first understand a few things. We must know what
the Rings in computer security are. Let’s take a look at the picture :
On the picture above, we can see four protection rings, which are mechanisms to protect data and
functionality from faults and malicious behavior. Each protection ring provides access to certain
resources within the computer system, which is generally hardware-enforced. The most
There are special gates between the outer rings to access the inner ring’s resources. Correctly
limiting access between rings can improve security by preventing programs from one ring or
privilege level from misusing resources intended for programs in another. Despite the picture
above showing four rings, only two are being used: ring 0 and ring 3 are for kernel and user
mode. If we would like to use protections rings successfully, the operating system must closely
work with the underlying hardware. But it’s often the case that operating systems are designed to
work on different hardware, so the operating system can only use a limited number of rings: in
most Windows systems, only 2 rings are used. When the process or a thread is being run by the
system, that process/thread has direct access to the privileged functions like accessing real
memory, modifying descriptor tables, disabling interrupts, etc… When we would like to use
kernel mode under Windows/Linux, we need to perform a system call into kernel mode where
the system call is executed and after that, the control is returned to the user space. The real
purpose of the kernel and user mode is to provide protection against system corruption. Let’s say
we’ve just written a program that tries to access some non-existent memory address like
0×00000000. In such cases, since the program is executing in the user mode, only the program
will crash; the system will be left unaffected. Now imagine what would happen if we wouldn’t
have different protections rings: one program like this can endanger the stability of the whole
system, in which case the whole system can crash. I’m not saying this can’t happen, because we
all know the Window’s blue screen of death, but this is a rare occurrence that is the result of a
bug in the Windows system. This is because the program misbehaves and a fault/exception is
generated in user mode, which doesn’t affect the stability of the system. But if a fault/exception
is generated in the kernel mode, the whole operating system can become unstable and crash the
computer.
When debugging, we must also be aware of the fact that all loaded modules the program needs
are still in user mode; so kernel32.dll, ntdll.dll and other DLLs are loaded in user-mode. Those
DLLs are just gateways into the kernel-mode, but they also provide the error handling and
parameter verification. This is because the kernel must receive a valid function call that can’t
endanger the stability of the system.
References: