OS by JJsir
OS by JJsir
OPERATING SYSTEMS
CONCEPTS WITH UNIX / LINUX
BY JJ SIR
What is OS?
What OS does?
Application Programs
System Programs
HARDWARE
(Contd…)
OS by JJsir
(Contd…)
OS by JJsir
3. System programs
This layer consists of compilers, Assemblers, linker etc.
4. Application programs
This is dependent on users need. Ex. Railway reservation
system, Bank database management etc.,
OS by JJsir
File Management: The operating system is responsible for organizing and managing
the file system, including the creation, deletion, and manipulation of files and
directories.
Device Management: The operating system manages input/output devices such as
printers, keyboards, mice, and displays. It provides the necessary drivers and
interfaces to enable communication between the devices and the computer.
Networking: The operating system provides networking capabilities such as
establishing and managing network connections, handling network protocols, and
sharing resources such as printers and files over a network.
User Interface: The operating system provides a user interface that enables users to
interact with the computer system. This can be a Graphical User Interface (GUI), a
Command-Line Interface (CLI), or a combination of both.
Backup and Recovery: The operating system provides mechanisms for backing up
data and recovering it in case of system failures, errors, or disasters.
OS by JJsir
Features of OS
Batch processing
History of batch
The earliest computers were extremely expensive devices, and very slow. Machines
were typically dedicated to a particular set of tasks and operated by control panel,
the operator manually entering small programs via switches in order to load and run
other programs. These programs might take hours, even weeks, to run. As computers
grew in speed, run times dropped, and suddenly the time taken to start up the next
program became a concern. The batch processing methodologies evolved to
decrease these dead times, queuing up programs so that as soon as one completed,
the next would start.
In Batch processing same type of jobs batch (BATCH- a set of jobs with similar needs)
together and execute at a time.
The OS was simple, its major task was to transfer control from one job to the next.
The job was submitted to the computer operator in form of punch cards. At some
later time the output appeared.
The OS was always resident in memory.
Common Input devices were card readers and tape drives.
OS by JJsir
Batch processing
OS by JJsir
Batch processing
Advantages
After input process is over, while processing is going on user can attend
other jobs.
It allows sharing of computer resources among many user and programs
It shifts time of job processing to when the computing resources are less
busy
Disadvantages
Difficult to provide priority scheduling
Access to one program is not possible
If result of particular program or time detail are required, you have to
wait till entire batch is processed
OS by JJsir
Multiprogramming
Multiprogramming
Job 3
Job 4
OS by JJsir
Multiprogramming
Advantages:
Time is not wasted in switching from one program to another
Many programs run at same time
Important and small jobs need not wait for batch
Disadvantages :-
OS is complicated because many programs are handle together
Advantages of TSOS
Allprograms get equal attention and small program get
over fast
Reduce CPU idle time
Disadvantages of TSOS
OS is more complicated
Advantages of RTOS :-
Accessand retrieval of record is quick
Response time is very less
Disadvantages of RTOS :-
Veryexpensive
Question of security
Applications
Stock market
Airline reservation system
OS by JJsir
Kali Linux
BlackBox
Parrot Security Operating System
Fedora Security Lab
DEFT Linux
Live Hacking Operating System
Network Security Toolkit (NST)
BlackArch Linux
Cyborg Hawk Linux
NodeZero
OS by JJsir
What is process?
Process
Process State
Process State
New or create :-
The process has been created
This is done when user types a name of a program to be executed
Ready or waiting :-
A "ready" or "waiting" process has been loaded into main
memory and is awaiting execution on a CPU There may be many
"ready" processes at any one point of the systems execution - for
example, in a one processor system, only one process can be
executing at any one time, and all other "concurrently executing"
processes will be waiting for execution.
Running :-
A process is an running state, if it has given all resources needed
for its execution
OS by JJsir
Process State
Blocked :-
The process is waiting some events to occur
Terminated :-
A process may be terminated, either from the "running"
state by completing its execution or by explicitly being
killed
OS by JJsir
Process State
Thisspecifies the process state i.e. new, ready, running,
waiting or terminated.
Process Number
This shows the number of the particular process.
Program Counter
This
contains the address of the next instruction that
needs to be executed in the process.
OS by JJsir
Registers
Thisspecifies the registers that are used by the process.
They may include accumulators, index registers, stack
pointers, general purpose registers etc.
List of Open Files
These are the different files that are associated with
the process
OS by JJsir
Context switching
Context switching
Threads
A thread is a single sequence stream within a process. Threads are also called
lightweight processes as they possess some of the properties of processes.
Each thread belongs to exactly one process. In an operating system that
supports multithreading, the process can consist of many threads.
But threads can be effective only if CPU is more than 1 otherwise two threads
have to context switch for that single CPU.
A thread shares with its peer threads few information like code segment, data
segment and open files. When one thread alters a code segment memory item,
all other threads see that.
Multi-threading
Multithreading is a technique used in operating systems to improve the performance and
responsiveness of computer systems. Multithreading allows multiple threads (i.e., lightweight
processes) to share the same resources of a single process, such as the CPU, memory, and
I/O devices.
OS by JJsir
Benefits of threads
Responsiveness: If the process is divided into multiple threads, if one thread completes
its execution, then its output can be immediately returned.
Faster context switch: Context switch time between threads is lower compared to the
process context switch. Process context switching requires more overhead from the CPU.
Effective utilization of multiprocessor system: If we have multiple threads in a single
process, then we can schedule multiple threads on multiple processors. This will make
process execution faster.
Resource sharing: Resources like code, data, and files can be shared among all threads
within a process. Note: Stacks and registers can’t be shared among the threads. Each
thread has its own stack and registers.
Communication: Communication between multiple threads is easier, as the threads
share a common address space. while in the process we have to follow some specific
communication techniques for communication between the two processes.
Enhanced throughput of the system: If a process is divided into multiple threads, and
each thread function is considered as one job, then the number of jobs completed per
unit of time is increased, thus increasing the throughput of the system.
OS by JJsir
Types of threads
1. User-level thread.
2. Kernel level thread.
Process Thread
Process means any program is in execution. Thread means a segment of a process.
The process takes more time to terminate. The thread takes less time to terminate.
It takes more time for creation. It takes less time for creation.
It also takes more time for context switching. It takes less time for context switching.
Process Scheduling
Process scheduling is a technique that is used when there are limited resources and
many processes are take part for execution;
If the system has more than one processor, then it is possible to execute more than
one process at the same time.
In a single processor system, only one process can be executed at any given time.
If there are more processes, then the operating system must schedule the processes.
It means that some processes will be executed and others will have to wait.
There are many strategies for deciding which process should be assigned to the
CPU.
OS by JJsir
Process Scheduling
Scheduling Queues
Below is a list of the most common types of queues and their purpose.
Job Queue - Each entering process goes into job queue. Processes in
job queue reside on mass storage and awaits the allocation of main
memory.
Ready Queue - The set of all processes that are in main memory and
are waiting for CPU time, are kept in ready queue.
Types Of Scheduling
Preemptive Scheduling :-
Preemptive is when a new process arrives, its burst time is
compared with time of currently executing process and if
a new process is having a shortest burst time then new
process is given the CPU time
FCFS
SJN
Round Robin
Priority Base Non Preemptive
Priority Base Preemptive
OS by JJsir
ms P1 P2 P3 P4 P5
In this CPU picks up 1st process from ready
queue, 0 ms 9 4 5 7 3
3 ms 6 4 5 7 3
set the timer and dispatch the process
6 ms 6 1 5 7 3
E.g.-if process and quantum time q = 3 then
9 ms 6 1 2 7 3
P1 9 15 ms 6 1 2 4 0
18 ms 3 1 2 4 X
P2 4
19 ms 3 0 2 4 X
P3 5
21 ms 3 X 0 4 X
P4 7
24 ms 3 X X 1 X
P5 3 27 ms 0 X X 1 X
TOTAL 28 28 ms X X X 0 X
P1 P2 P3 P4 P5 P1 P2 P3 P4 P1 P4
3 6 9 12 15 18 19 21 24 27 28
OS by JJsir
OPERATING SYSTEMS
BY JJ SIR
Deadlock
Deadlock Prevention:
The idea is to not let the system into a deadlock state.
This system will make sure that above mentioned four conditions will not
arise.
These techniques are very costly so we use this in cases where our
priority is making a system deadlock-free.
One can zoom into each category individually, Prevention is done by
negating one of the above-mentioned necessary conditions for
deadlock.
Deadlock Avoidance:
Avoidance is kind of futuristic.
By using the strategy of “Avoidance”, we have to make an
assumption.
We need to ensure that all information about resources that the
process will need is known to us before the execution of the process.
In prevention and avoidance, we get the correctness of data but
performance decreases.
OS by JJsir
Deadlock Detection :
A deadlock can be detected by a resource scheduler as it keeps
track of all the resources that are allocated to different processes.
After a deadlock is detected, it can be resolved using the following
methods −
All the processes that are involved in the deadlock are
terminated. This is not a good approach as all the progress made
by the processes is destroyed.
Resources can be preempted from some processes and given to
others till the deadlock is resolved.
OS by JJsir
Physical Memory:
Physical memory is the actual real memory used in RAM.
Physical memory is the only memory that is directly accessible to the CPU.
CPU reads the instructions stored in the physical memory and executes them
continuously.
The data that is operated will also be stored in physical memory in uniform
manner.
Virtual Memory:
Virtual memory as the name suggests is not real.
The OS uses virtual memory as a memory management technique in which
non- contiguous memory is presented to software as contiguous memory.
Virtual memory is one classification of memory which was created by using
the hard disk for simulating additional RAM, the addressable space
available for the user.
Virtual addresses are mapped into real addresses.
OS by JJsir
Memory Allocation
Memory Allocation
Fragmentation
Types of fragmentation
1. External fragmentation
2. Internal fragmentation
OS by JJsir
External fragmentation
External fragmentation exists when total memory space
exists to satisfy a request, but it is not contiguous; storage
is fragmented into many holes.
Internal fragmentation
An approach is to allocate small holes as part of the
larger request. Thus, the allocated memory may be larger
than the requested memory.
OS by JJsir
Paging is based on the concept of dividing the programs into equal sized blocks called pages and
the main memory is divided into equal sized blocks known as frames.
Generally the size of the page is equal to size of the frames so that there is no internal
fragmentation.
Its not necessary that these frames are in sequence
To know which page is loaded in which frame, for that page map table is used (PMT)
PMT has two entries page number and its respective frame number. Each job will have its unique
PMT.
This PMT also store somewhere in the memory and it has its own location and address.
This location of PMT is stored in another table known as job table
It contains two entries job number and location of PMT for each job
Third table which is used is Memory Map Table (MMT)
This table keeps track of free and busy frames in the main memory.
Whenever new job arrives and new frames have to be allocated to this job, only those frames which
are free or unallocated to any jobs can be allocated to this job.
Memory Map Table contains the frame numbers and its status of free or busy
OS by JJsir
OPERATING SYSTEMS
BY JJ SIR
Unix Architecture
Unix Architecture
Feature of Unix
Multi user
Multi tasking
Portable
Pattern Matching
Tool Kit
Programming Facility
System calls & Libraries
Window system
Documentation
Networking
Organized file system
Device Independence
OS by JJsir
Shell
BOURNE C Korn
Bash tcsh
OS by JJsir
Bourn Shell
C Shell
C Shell
It checks the command for the redirected files and verifies the
files.
If wildcard characters are found, shell replaces it with the
original file names.
It uses the path variable to locate the directory containing the
actual command.
OS by JJsir
Korn Shell
Types of files
Ordinary File
This file also known as Regular file and its also most common type
of file
It can be a program code, executable file, data file or external
Unix command
These regular files can store data either in text or binary format.
The most common type is the text file.
The data stored in these file is divided into group of lines
separated by the newline character.
Another type of file is binary file. These are stored in the internal
format containing the application data.
There are two types of binary files data files and program files.
A program file contains the set of instructions which can be
executed one after another
OS by JJsir
Directory files
Device Files
The Unix file system allows you to control read, write & execute access to
your files
Basic permission :-
1) Read permission :-
Which grant the ability to read a file
2) Write permission :-
Which grant the ability to modify a file when set for directory, this permission grant
the ability to modify entries in directory
This includes creating files, deleting & renaming files
3) Execute permission :-
Which grant the ability to execute a file.
Since the unix/linux multi user system, the users are given their
own username by the system administrator
User has to enter username and password when the prompt
appears on the screen
Login incorrect
Wait for login retry
Login :
After successful login system will show $ as a prompt. If you are the
system administrator and logged in as root, it will give the prompt #
In LINUX prompt will be
[root@localhost]#
Which shows you are logged in as root and your machine is local host
Logout is used to signoff a system as current user
OS by JJsir
Password command
Ls
This command is use to give list of files and directories created by user and
default
Ls enter
Clear
To clear command prompt use clear to clear screen
To clear with short cut key use ctr+l
Ctrl + p
You can use a combination of 'CTRL + P' and 'CTRL + R' to output the last
command that you used on the terminal.
Pwd
Pwd means Present(Print) woking Directory
This command use to give current location of the user
Pwd enter
OS by JJsir
cp - copying files
eg. cp file1 file2 jj/
-i : Interactive copy.1
If the destination file already exists then interactive copy asks the user
whether the file should be overwritter or not? yes/no. If no is specified then
the copy command is terminated
eg. cp -i file1 jj/
-r : Recursive copy.
It copies directory and its all sub directories and all files contained in
it to new directory. If the destination directory does not exist then first the
directories are created then the files are copied to them.
eg. cp -r jj /kd
cp * kd/
It copies all files to directory
OS by JJsir
Mv command :-
Mv Command is use to rename directory and file another use of mv command is to move file and
directory in particular folder
Rename
Mv oldfilename newfilename
Mv a abc (it will change name a from abc)
Mv –i
When this command use with –i it will asks for overwrite if file already exist
Mv –i a b/
Mv –f
When this command use with –f it will not ask for overwrite if file already exist
Mv –f a b/
Mv *
move all files and directory to puticular folder
Mv * b/
OS by JJsir
Rmdir
It removes directory if directory is empty
Rmdir d
Rm
This command is use to remove file
Rm f1
Rm -i
When rm use with –I it will ask before delete
Rm –I f (it will ask user before delete if user type y it will delete if n
then file will not delete)
Rm –r
If rm command use with –r user can remove directory and its
subdirectories with all content
Rm –r d
OS by JJsir
Chgrp command:
The `chgrp` command in Linux is used to change the
group ownership of a file or directory. All files in
Linux belong to an owner and a group.
Chgrp [option] filename
Chown command:
The chown command in Linux changes user ownership
of a file, directory, or link(soft link or hard link) in
Linux.
chown –version
OS by JJsir
Chmod command
Chmod command
Chmod command
Operators Definition
Chmod command
Chmod command
Reference Class
u Owner
g Group
o Others
a All (owner,groups,others)
OS by JJsir
Chmod command
touch command:
It is used to create a file without any content.
The file created using the touch command is empty.
This command can be used when the user doesn’t
have data to store at the time of file creation.
Touch filename
Ln command:
The ln command is used to create links between files.
ln -s sourcefile symboliclink
OS by JJsir
Stat Command:
Alias command:
alias are like custom shortcuts used to represent a command (or set
of commands) executed with or without custom options.
It is like a shortcut command which will have same functionality as if
we are writing the whole command.
The syntax for creating an alias is:
alias name="value"
$ alias .=cd
To see all defined aliases in a reusable format, we can use the -
p option.
$ alias -p
OS by JJsir
Remove alias:
We can remove an alias by using
the unailas command.
syntax: unalias [alias name]
$ unalias vi
Find command: This command examines the
directory tree to for files matching the criteria and
then takes action on the selected files
$find filename
OS by JJsir
Type command:
The type command is used to describe how its
argument would be translated if used as commands.
It is also used to find out whether it is built-in or
external binary file.
Syntax:
type [Options] command names
Example:
OS by JJsir
Type (Option)
Type (Option)
Operators
All consist of plain text and are considered as type of text file, and
all are associated with console (text mode display screen by
default)
Operators in Redirection
Standard output and standard error are the destination of output and
error messages from command but they can be redirected to go other
destination (file, printer or another program)
Redirection device can be classified into 2 categories :
1) argument
2) redirection operators
Arguments is the name of file or other data that is provided to command in
order for command to use it as input and it redirects standard I/P from
being the keyboard to that file or data
Example :- if you want to read single file data then argument will be
$ head file1
Standard I/P could just as easily redirected with multiple argument
Eg –$ head file1 file2 file3
It this case head will by default read the 1st 10 lines from each file and
write them to display screen
OS by JJsir
Operators in Redirection
Redirection operator :-
1) I/p
2) O/P
3) Error
To redirect standard I/p, so that command obtains its I/p from a file instead
of keyboard, the I/P redirection operator, which is represented by leftward
point angular bracket, cant be used(<)
Eg – the standard I/p for head can be redirected to file named file 4 with
the following
$ head < file 4
And same by using argument
$ head file 4
OS by JJsir
Operators in Redirection
Operators in Redirection
Operators in Piping
Syntax
Grep options pattern filename
Eg. :- grep ch JJ
Arguments
i – ignoring the case. Eg grep –i th jj
w - grep makes it match only the whole words.
Eg. grep -w "unix" jj
c – counting the occurances. Eg. grep –c th jj
I – displaying the file names. Eg. grep –l th *.txt
n – displaying the line number. Eg. grep –n th jj
^ - This can be used in grep to match the lines which start
with the given string or pattern. Eg. Grep “^o” jj
Bytes Arguments
Bytes Arguments
Eg. Eg.
List without ranges List with ranges
cut -b 1,2,3 state $ cut -b 1-7 state
And Andra
Aru Aruach
Ass Assm
Bih Bihr
Chh Chhtti
cut -b 1- state $ cut -b -3 state
OS by JJsir
Character argument
Character argument
Paste
Join
eg. sort jj
eg. sort -r jj
OS by JJsir
Sort a column
Numeric Sorting
Uniq command
This command is used to selects non repeated line and removes other
duplicate lines from the output
-u It removes duplicate lines and displays only the uniq lines from the file
eg. uniq -u jj
eg. uniq -d jj
eg. uniq -c jj
OS by JJsir
Comparing files
Cmp command:
This command compares two files byte by byte the
first byte of first file compare with first byte of
second file
cmp jj dj
OS by JJsir
Comm command
This command is useful to compare two files line by line and displaying the common lines between
these files
eg. comm jj dj
the output consists of three columns the first column is the lines which are unique to the first file.
the second column displays the lines which are unique to the second file.
the third column displays the lines which are common between both files.
Output
a e
b
c
d f
OS by JJsir
Diff command
Diff command
d : delete
OS by JJsir
Diff command
Diff command
(Translate/ tr Command)
-c option
-d option
Delete characters
-s option
SED command
Syntax:
sed OPTIONS... [SCRIPT] [INPUTFILE...]
OS by JJsir
eg. bc
12*2 <enter>
24
ctr+d
OS by JJsir
factor
eg. factor
12<enter>
12:2 2 3
20<enter>
20 : ???
ctr+d
OS by JJsir
Monitoring Input and Output
(Tee command)
tee - tee is normally used to split the output of a program so that it can be
both displayed and saved in a file.
The command can be used to capture intermediate output before the data
is altered by another command or program.
The tee command reads standard input, then writes its content to standard
output.
Script
script - with use of script command you can record your session.
To end script just type exit it will exit from started script.
eg. cal
eg. cal 8 2016
eg. cal 2018
eg cal -j
cal -j : It displays the Julian dates as 1st Jan as 01 and 31st Dec as 365
OS by JJsir
Date
Example
date
Example
date "+ %d %m %y"
OS by JJsir
Communications (Telnet)
Wall
Write
Example
Write (username)
OS by JJsir
News
Finger
Mesg
Eg.mesg [y|n]
OS by JJsir
Ping
Ps
Ps stands for Process Status
This command displays the information about the active
processes.
Eg. Ps
Kill
This command terminates the process associated with the
specified pid value.
If more than one process has to be terminated it can be
done by single statement by specifying pid of all the
processes
Eg. Kill 5254 5290 5230…..
OS by JJsir
Nice :-
Runs a command with a modified scheduling priority.
nice runs command COMMAND with an adjusted "niceness",
which affects process scheduling.
A process with a lower niceness value is given higher priority
and more CPU time. A process with a higher niceness value
(a "nicer" process) is given a lower priority and less CPU
time, freeing up resources for processes which are more
demanding.
Niceness values range from -20 (most favorable to the
process) to 19 (least favorable to the process).
With no COMMAND, nice prints the current niceness level.
OS by JJsir
Batch and At
Batch invoke at command
The at command schedules a command to be run once at a particular time.
This can be any command that you normally have permission to run;
anything from a simple reminder message, to a complex script.
You start by running the at command at the command line, passing it the
scheduled time as the option.
It then places you at a special prompt, where you can type in the command
(or series of commands) to be run at the scheduled time.
When you're done, press Control-D on a new line, and your command will
be placed in the queue.
Wait
wait is a built-in shell command which waits for a
given process to complete, and returns its exit status.
Eg. Wait [pid]
sleep
The sleep command is used to delay for a specified
amount of time.
Eg. Sleep 10
OS by JJsir
jobs
The jobs command allows you to view a list of all jobs running in the
background or suspended in the current shell.
Eg. $jobs
top
The top command displays all the running process within the
environment of your system.
It helps in monitoring system usage and performances. It is mainly
used to detect load on the server by system administrators.
The top command stands for table of processes.
Eg. top
OS by JJsir
Mount
The mount command mounts a storage device
or filesystem, making it accessible and attaching it
to an existing directory structure.
Unmount
The umount command "unmounts" a mounted
filesystem, informing the system to complete any
pending read or write operations, and safely
detaching it.
OS by JJsir
OPERATING SYSTEMS
BY JJ SIR
Introduction of vi editor
Modes in vi
Command mode
Input mode in vi
Switching mode in VI
While you start VI editor at that time you will be at vi mode that will ready to accept
defined command on that particular key but not any input.
If you want to input text into the file you will have to go to input mode for that you
will have to press “i”.
If you will press “i” at VI mode you will be at input mode here you can input any data
into the file from this mode if you want to switch to vi mode then you will have to
press “Esc” key.
If you will press “Esc” key at input mode you will be able to switch to vi mode.
If you want to switch to command mode from the VI mode then you will have to press
“:” or “/” that will support you to switch you from VI mode to command mode.
If you want to switch to command mode from the input mode then you will have to
first come to the VI mode then you will be able to switch to command mode.
To switch from input mode to command mode then you first will have to press “Esc”
key and then after you will have to press “:” or “/” key that will support you to switch
from input mode to command mode via VI mode.
OS by JJsir
UNDO REDO in vi
UNDO REDO in vi
To save a file
To save a file
OS by JJsir
Ctrl+w is used.
Press Ctrl+w
It will ask for a word to search for.
Enter the word
It will search for the word and will place the cursor in
the first letter of the first occurrence of the word.
OS by JJsir
Shell Keywords
Shell Variables
Shell Variables
System Variables
These variables are used to configure the environment during the boot sequence or
after user login, so they are also known as environment variables.
The shell has two prompts stored in PS1 and PS2.
PS1: It is the primary prompt string like $ or %. The shell uses the primary prompt when
the command is expected by the shell. For changing the value of this prompt, we can
use PS1= ‘@’.
As soon as it is set the new prompt is displayed. It can be restored back to $ prompt as
PS1=“$”.
PS2: It is the secondary prompt; it is used when the command entered on the first line
was not able to be completed. The default prompt is >.
PATH: Searches the path for commands. If $PATH is not set then the current directory,
/bin and /usr/bin are searched by default. Otherwise $PATH consists of directory
names
separated by:
For Example: PATH=:/usr/Bhavik/bin:/bin:/usr/bin
OS by JJsir
System Variables
HOME: It is path name for the home directory. When the user logs in the
system, unix normally places the user in home directory or login directory and
is the path stored in variable HOME.
The change the default argument for the cd command.
For Example: cd /usr/Bhavik/bin
LOGNAME: It contains login name which is stored in the passwd file. This
variable shows your username only while Who am I also displays the user
name with the terminal type and login name.
MAIL: It displays the absolute path name of user’s mailbox and determines
where all incoming mail addressed to the user is to be stored. This variable is
typically set in the file .profile, in the user’s login directory.
For Example: MAIL=/var/spool/mail/root
OS by JJsir
System Variables
IFS: This variable contains internal field separators. These are the characters that
separate
the parameters and commands. These separators include space, tab and newline.
Default
separator is space.
SHELL: This variable contains the pathname of login shell. Various shells available in
unix system include korn shell, bash shell or c shell. User can select any one from them.
TERM: It indicates the Terminal type being used. The value of this variable can be
utilised by VI command. The VI editor makes the use of the control file in the directory
/usr/lib/terminfo.
MAILCHECK: It contains Interval between tests for new email. The default is 600
seconds. When the user logs in, shell checks mail file to determine if there is new mail.
If mail is there, it display “You have a mail”.
OS by JJsir
Positional Parameters
A positional parameter is a variable within a shell program; its value is set from an argument
specified on the command line that invokes the program.
Positional parameters are numbered and are referred to with a preceding ``$'': $1, $2, $3, and
so on.
Example:
$sh filename.sh first second third fourth fifth sixth seventh eighth ninth
$0 $1 $2 $3 $4 $5 $6 $7 $8 $9
Arguments are user supplied data that follow the file name on the command line and are input to
the shell script.
Positional Parameters are predefined memory variables in the shell scripts.
There are nine positional parameters $1, $2……. $9 that are used to store the user arguments.
The file name is stores in $0.
When script is executed the shell puts the first argument in first positional parameter $1, second
argument in second positional parameter $2 and so on
OS by JJsir
The read command is a shell built-in command for reading data from a file or keyboard.
The read command receives the input from the keyboard or a file until it receives a newline character. Then, it
converts the newline character into a null character:
1. Read a value and store it in the variable, shown as follows:
2. read variable
3. echo $variable
This will receive text from the keyboard. The received text will be stored in the variable.
4. Command read with prompt. Whenever we need to display the prompt with certain text, we use the –p
option. The option -p displays the text that is placed after –p on the screen:
5. #!/bin/bash
6. # following line will print "Enter value: " and then read data
7. # The received text will be stored in variable value read -p "Enter value : " value
Output:
Enter value : abcd
8. If the variable name is not supplied next to the read command, then the received data or text will be stored
in a special built-in variable called REPLY.
OS by JJsir
The if...elif...fi statement is the one level advance form of control statement that
allows Shell to make correct decision out of several conditions.
Syntax
Case Syntax
case word in
pattern1)
Statement(s) to be executed if pattern1 matches
;;
pattern2)
Statement(s) to be executed if pattern2 matches
;;
*)
Default condition to be executed
;;
esac
OS by JJsir
Test command
The test command is used to check file types and compare values. Test is used in conditional
execution.
Syntax:
test condition
OR
test condition && true-command
OR
test condition || false-command
OR
test condition && true-command || false-command
Example :
Type the following command at a shell prompt (is 5 greater than 2? ):
test 5 -gt 2 && echo "Yes"
test 1 -lt 2 && echo "Yes"
Sample Output:
Yes
Yes
OS by JJsir
Logical Operator
Logical Operators: They are also known as Boolean operators. These are used to perform logical operations.
They are of 3 types:
Logical AND (&& / -a): This is a binary operator, which returns true if both the operands are true otherwise
returns false.
Logical OR (|| / -o): This is a binary operator, which returns true is either of the operand is true or both the
operands are true and returns false if none of them is false.
Not Equal to (!): This is a unary operator which returns true if the operand is false and returns false if the
operand is true.
Example:
# take a number from the user
echo "Enter a number: "
read a
# check
if [ `expr $a % 2` == 0 -a $a -gt 10 ]
then
echo "$a is even and greater than 10."
else
echo "$a failed the test."
fi
OS by JJsir
For loop
syntax :
For((statement 1, statement 2, statement 3))
Do
Statements to be excute
Done
While loop
Until loop
Syntax :
until [condition]
do
Statement(s) to be executed if condition is true
done
Break statement
Continue statement
It terminates the execution of the It skips the execution of the loop for
1
loop for all the remaining iterations. only the current iteration.
Array
1. Indirect Declaration
In this method, you assign a value to a specific index of the array variable.
There’s no need to declare the array beforehand.
ARRAYNAME[INDEXNR]=value
2. Explicit Declaration
With explicit declaration, you first declare the array and then assign values
to it.
declare -a ARRAYNAME
3. Compound Assignment
This method involves declaring the array along with its initial set of values.
You can later add additional values to the array.
ARRAYNAME=(value1 value2 .... valueN)
OS by JJsir
Example:
Following example shows the use of function −
# Define your function here
Hello ()
{
echo "Hello World“
}
# Invoke your function
Hello
OS by JJsir
You can define a function that will accept parameters while calling
the function.
These parameters would be represented by $1, $2 and so on.
OPERATING SYSTEMS
BY JJ SIR
CH-5 : GETTING STARTED WITH LINUX, LINUX BOOTING, LINUX ADMIN (UBUNTU)
OS by JJsir
Unix
History
Characteristics of UNIX
Advantages of UNIX
Disadvantages of UNIX
Before Linux
GNU project
Beginning of Linux
Linux
Characteristics of Linux
Advantages of Linux
Disadvantages of Linux
Structure of linux
1. Kernel:
Kernel is the main core component if Linux, it controls the activity of
other hardware components. It visualizes the common hardware resources and
provide each process with necessary virtual resources. It makes the process to wait
in the ready queue and execute in consequently to avoid any kind of conflict.
2. System Library:
System libraries are some predefined functions by using which any application
programs or system utilities can access kernel’s features. These libraries are the
foundation upon which any software can be built.
3. Shell:
Shell can be determined as the interface to the kernel, which hides the internal execution of functions of kernel from the user.
Users can just enter the commend and using the kernel’s function that specific task is performed accordingly.
4. Hardware Layer:
Hardware layer of Linux is the lowest level of operating system track. It is plays a vital role in managing all the hardware
components. It includes device drivers, kernel functions, memory management, CPU control, and I/O operations. This layer
generalizes hard complexity, by providing an interface for software by assuring proper functionality of all the components.
5. System utility:
System utilities are the commend line tools that preforms various tasks provided by user to make system management and
administration better. These utilities enables user to perform different tasks, such as file management, system monitoring,
network configuration, user management etc.
OS by JJsir
Feature of linux
Shutdown:
If you are going to initiate a shutdown of your system
and there are other users logged in to your system, it is
always polite to notify them first.
To do this, we would use the shutdown command. The
shutdown command will accept times and a broadcast
message:
shutdown [options] time [warning_message]
shutdown and reboot immediately
$ shutdown -r now
OS by JJsir
1. BIOS
BIOS stands for Basic Input/Output System
Performs some system integrity checks
Searches, loads, and executes the boot loader program.
It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it
depends on your system) during the BIOS startup to change the boot sequence.
Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
So, in simple terms BIOS loads and executes the MBR boot loader.
2. MBR
MBR stands for Master Boot Record.
It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2)
partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
It contains information about GRUB (or LILO in old systems).
So, in simple terms MBR loads and executes the GRUB boot loader.
OS by JJsir
3. GRUB
GRUB stands for Grand Unified Bootloader.
If you have multiple kernel images installed on your system, you can choose which one to
be executed.
GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads
the default kernel image as specified in the grub configuration file.
GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand
filesystem).
Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The
following is sample grub.conf of CentOS.
4. Kernel
Mounts the root file system as specified in the “root=” in grub.conf
Kernel executes the /sbin/init program
Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of
1. Do a ‘ps -ef | grep init’ and check the pid.
initrd stands for Initial RAM Disk.
initrd is used by kernel as temporary root file system until kernel is booted and the real
root file system is mounted. It also contains necessary drivers compiled inside, which helps it
to access the hard drive partitions, and other hardware.
OS by JJsir
5. Init
Looks at the /etc/inittab file to decide the Linux run level.
Following are the available run levels
0 – halt
1 – Single user mode
2 – Multiuser, without NFS
3 – Full multiuser mode
4 – unused
5 – X11
6 – reboot
Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
6. Runlevel programs
When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail ….
OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
Depending on your default init level setting, the system will execute the programs from one of the following directories.
Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 2 – /etc/rc.d/rc2.d/
Run level 3 – /etc/rc.d/rc3.d/
Run level 4 – /etc/rc.d/rc4.d/
Run level 5 – /etc/rc.d/rc5.d/
Run level 6 – /etc/rc.d/rc6.d/
Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to
/etc/rc.d/rc0.d.
OS by JJsir
LILO Configuration
LILO (LInux LOader) is a boot loader for use with the Linux operating system.
Most new computers are shipped with boot loaders for some version of
Microsoft Windows or the Mac OS.
If a computer is to be used with Linux, a special boot loader must be installed.
LILO is the most popular boot loader among users who employ Linux as their main,
or only, operating system.
When a computer is powered-up or restarted with LILO installed in the usual
manner, the basic input/output system (BIOS) performs some initial tests and then
transfers control to the Master Boot Record (MBR) where LILO resides.
The primary advantage of LILO is the fact that it allows for fast boot up of Linux
when installed in the MBR.
Its main limitation is the fact that not all computers tolerate modification of the MBR.
In these situations, there are alternative approaches for using LILO, but it takes
longer.
OS by JJsir
GRUB configuration
LILO GRUB
LILO has no interactive command interface GRUB has interactive command interface
LILO does not support booting from a network GRUB does support booting from a network
If you change your LILO config file, you have to GRUB automatically detects any change in
rewrite the LILO stage one boot loader to the config file and auto loads the OS
MBR
LILO supports only linux operating system GRUB supports large number of OS
LILO supports only up to 16 different boot GRUB supports an unlimited number of boot
selections entries.
OS by JJsir
To create a new user in Linux, use the adduser command. The following is the syntax
to create.
sudo adduser newusername
The sudo is a program for computer operating system such as Linux, Linux that
allows users to run programs with the security privileges of another user, by default
the Superuser.
The name is combination of “Do as Su” where “Su” is for “Super user”.
After typing that command following process started by Linux:
Type and confirm password.
Enter in the user’s information. This is optional. Press enter key to automatically fill
the field with the default information.
Press Y (or Enter key) when asked to confirm the information.
You have just added a new user to your Ubuntu operating system.
OS by JJsir
LDAP Services
DNS Services
FTP Services
Web Services
Firewall is considered as the first method of defense in securing your cloud server.
Ubuntu includes its own (built-in) Firewall known as UFW.
UFW stands for “Uncomplicated Firewall”.
Its main goal is to provide an easy-to use interface.
The firewall is disabled by default. To enable the firewall, run the following commands from a
terminal. sudo ufw enable
To install Firewall: sudo aptitude install ufw Or sudo apt-get install ufw
To check the status, use following command: sudoufw status
Setup rules
You should first define some rules for the firewall for allowing and denying connection.
To set the defaults used by UFW, use the following commands sudo ufw default deny
incoming And sudo ufw default allow outgoing.
If you want to deny the outgoing request also, use the following command: sudo ufw default
deny outgoing.
Enable the SSH connection, use this command: sudo ufw allow ssh
OS by JJsir
OPERATING SYSTEMS
BY JJ SIR
BEST OF LUCK FOR EXAM
CREATED BY :- DIGRAJSINHSOLANKI.COM