Practical File
Practical File
OPERATING SYSTEMS
INDEX
Sr. Topic Remark
no.
1. Introduction to OS
2. Scheduling
3. Introduction to Linux and
Shell
4. Shell Commands
5. MS-DOS
Signature
1.
Introduction to OS
Operating system can be defined as the software that controls the
operation of a computer and directs the processing of programs by assigning
storage space in memory and controlling input and output functions. In other
words, an operating system is a powerful and usually extensive program that
controls and manages the hardware and other software on a computer.
Operating system controls the operation of a computer, directs the input and
output of data, keeps track of files, and controls the processing of computer
programs. Its roles include managing the functioning of the computer
hardware, running the applications programs, serving as an interface between
the computer and the user, and allocating computer resources to various
function.
CPU scheduling
Process scheduling is a task of operating system to schedules the processes
of different states like ready, running, waiting. This task is very useful in
maintain the computer system. Process scheduling allocates the time
interval of each process in which the process is to be executed by the
central processing unit (CPU). Process scheduling is very important in
multiprogramming and multitasking operating system, where multiple
processes execute simultaneously. Process scheduling ensures maximum
utilization of central processing unit (CPU) because a process is always
running at the specific instance of time. At first, the processes that are to be
executed are placed in a queue called Job queue. The processes which are
already placed in the main memory and are ready for CPU allocation, are
placed in a queue called Ready queue. If the process is waiting for input /
output, then that process is placed in the queue called Device queue.
Operating system performs the task of scheduling processes based on
priorities using
1. First come first serve (FCFS)
In this scheduling algorithm the first process entered in queue is
processed first.
2. Shortest job first (SJF)
In this scheduling algorithm the process which requires shortest CPU
time to execute is processed first.
3. Priority scheduling
In this scheduling algorithm the priority is assigned to all the processes
and the process with highest priority executed first. Priority assignment
of processes is done on the basis of internal factor such as CPU and
memory requirements or external factor such as user’s choice. The
priority scheduling algorithm supports preemptive and non - preemptive
scheduling policy.
4. Round Robin (RR) scheduling
In this algorithm the process is allocated the CPU for the specific time
period called time slice, which is normally of 10 to 100 milliseconds. If
the process completes its execution within this time slice, then it is
removed from the queue otherwise it has to wait for another time slice.
DISC SCHEDULING
"Disk Scheduling Algorithms" in an operating system can be referred to
as a manager of a grocery store that manages all the incoming and outgoing
requests for goods of that store. He keeps a record of what is available in-
store, what we need further, and manages the timetable of transaction of
goods.
The 'Disk Structure in OS' is made in such a way that there are many layers of
storage blocks on the disk. When we need to access these data from disk, we
initialize a 'request' to the system to give us the required data. These requests
are done on a large scale. So, there is a large number of input and output
requests coming to the disk.
The operating system manages the timetable of all these requests in a proper
algorithm. This is called a "Disk Scheduling Algorithm in OS". This algorithm
helps OS to maintain an efficient manner in which input-output requests can
be managed to execute a process. It manages a proper order to deal with
sequential requests to the disk and provide the required data. Since multiple
requests are approaching the disk, this algorithm also manages the upcoming
requests of the future and does a lining up of requests.
Types of Disk Scheduling
1. FCFS disk scheduling algorithm: It stands for 'first-come-first-serve'. As
the name suggests, the request that comes first will be processed first
and so on. The requests coming to the disk are arranged in a proper
sequence as they arrive. Since every request is processed in this
algorithm, so there is no chance of 'starvation'.
2. SSTF disk scheduling algorithm : It stands for 'Shortest seek time first'.
As the name suggests, it searches for the request having
the least 'seek time' and executes them first. This algorithm has less
'seek time' as compared to the FCFS Algorithm.
3. SCAN disk scheduling algorithm: In this algorithm, the head starts to
scan all the requests in a direction and reaches the end of the disk.
After that, it reverses its direction and starts to scan again the
requests in its path and serves them. Due to this feature, this
algorithm is also known as the "Elevator Algorithm".
Page replacement
Page replacement is a crucial concept in computer memory management,
particularly in the context of virtual memory systems used by modern
operating systems like Windows, Linux, and macOS. Virtual memory allows the
operating system to use a combination of RAM (physical memory) and disk
space (paging file or swap space) to provide a larger, contiguous, and
addressable memory space for running applications and processes.
Effective page replacement is essential for optimizing memory usage,
minimizing page faults, and ensuring optimal system performance in virtual
memory systems. Operating systems employ sophisticated page replacement
algorithms and memory management techniques to balance memory
utilization, performance, and responsiveness based on system resources,
workload characteristics, and user requirements.
Types of Page replacement
FIFO (First-In, First-Out):This algorithm replaces the oldest page in
memory, based on the assumption that the oldest page is least likely to
be needed in the near future.Simple and easy to implement.May suffer
from the "Belady's Anomaly," where increasing the number of page
frames can lead to an increase in the number of page faults.
LRU (Least Recently Used): This algorithm replaces the page that has not
been accessed for the longest time, based on the principle that recently
used pages are more likely to be used again in the near future.Effective
for applications with temporal locality (frequent reuse of recently
accessed pages) and can minimize the number of page faults.Requires
additional tracking and maintenance of access timestamps or counters
for each page, which can be computationally expensive.
LFU (Least Frequently Used): This algorithm replaces the page that has
been accessed the least number of times, based on the assumption that
less frequently used pages are less likely to be needed in the
future.Focuses on removing pages that are less likely to be used, which
can be beneficial for applications with spatial locality (access to a specific
set of pages at a time).Requires tracking and maintenance of access
frequencies or counters for each page, which can be complex and may
not always reflect future access patterns accurately.
Optimal Page Replacement: This algorithm replaces the page that will
not be used for the longest time in the future, based on a lookahead
prediction of future memory accesses.Serves as an ideal benchmark for
evaluating the performance of other page replacement
algorithms.Impractical to implement in real systems due to its predictive
nature and requirement to know future memory access patterns.
Clock (Second-Chance): This algorithm maintains a circular list (or
"clock") of page frames and uses a "use" bit or reference bit to identify
and replace the oldest page that has not been accessed recently.
Balances simplicity and effectiveness by considering recent access
history without the need for detailed tracking of access timestamps or
frequencies. May not always accurately reflect future access patterns or
prioritize pages based on access recency effectively.
Random Page Replacement: This algorithm randomly selects a page from
memory to replace when a page fault occurs .Simple and easy to
implement, and may perform well in certain scenarios or workloads.
Does not consider access patterns or prioritize pages based on usage
history, which can lead to suboptimal performance and unpredictable
behavior .
3.
Introduction to Linux and Shell
4.
Shell Commands
1) MAN: man command in Linux is used to display the user manual of any
command that we can run on the terminal. It provides a detailed view of the
command which includes NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXIT
STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS and
SEE ALSO. man command syntax:
man [option] [section number] [command name]
option – the search result output.
section number – the section in which to look for the man page.
command name – the name of the command which man page you want
to see.
Example :
a.
2) WHO: who command is a tool print information about users who are
currently
logged in. who command only see a real user who logged in.
6) CAT: The cat command is a vital tool for handling files and their contents in
the context of Linux and Unix-like operating systems. Cat is a shortcut for
"concatenate" and is used for a number of file generation, viewing, and
modification tasks.
7) LS: The ls command line utility lists all the files and directories under a
specified directory. By default, ls uses the current directory and lists files and
directories in alphabetical order by name. The ls command supports many flags
that modify its behavior.
8) CP: The cp command in Linux is used to copy files and directories from one
location to another within the filesystem. It allows users to duplicate files,
create backups, and manage data efficiently
9) MV: The mv command works with files and directories, yielding different
results depending on the used arguments. There are four basic ways to execute
an mv command:
10) RM: The rm command can delete files, groups of files, directories, or
complete directory trees.
11) PWD: The pwd command writes to standard output the full path name of
your current directory (from the root directory). All directories are separated
by a / (slash). The root directory is represented by the first /, and the last
directory named is your current directory.
12) CD: The 'cd' command is one of the most basic yet essential commands in
Linux. It stands for 'change directory', and as the name suggests, it allows you
to change your current working directory.
13) MKDIR: The mkdir command creates directories. This command can create
multiple directories at once as well as set the permissions for the directories. It
is important to note that the user executing this command must have enough
permissions to create a directory in the parent directory.
14) RMDIR: The rmdir command is used remove empty directories from the
filesystem. The rmdir command removes each directory specified in the
command line, but only if the directory is empty. Directories that have sub-
directories or files within them will not be removed.
15) WC: wc (short for word count) is a command line tool in Unix/Linux
operating systems, which is used to find out the number of newline count,
word count, byte and character count in the files specified by the File
arguments to the standard output and hold a total count for all named files.
16) DATE: Linux date command displays and sets the system date and time.
This command also allows users to print the time in different formats and
calculate future and past dates.
17) CAL: The cal command in Linux is used to display a simple calendar in the
terminal. By default, it shows the calendar for the current month. You can
specify a particular month or year to display.
18) DIFF: diff is a command-line utility that allows you to compare two files line
by line. It can also compare the contents of directories. The diff command is
most commonly used to create a patch containing the differences between one
or more files that can be applied using the patch command.
19) UNIQ: Linux uniq command is used to remove all the repeated lines from a
file. Also, it can be used to display a count of any word, only repeated lines,
ignore characters, and compare specific fields.
20) GREP: Grep is a useful command to search for matching patterns in a file.
grep is short for "global regular expression print".
21)Sort : Suppose you have a text file which contains the names of dogs
The weird strings you see on each file line, like drwxr– xr–x , define the
permissions of the file or folder.
Let's dissect it.
The first letter indicates the type of file:
–means it's a normal file
d means it's a directory
l means it's a link
Then you have 3 sets of values:
• The first set represents the permissions of the owner of the file
• The second set represents the permissions of the members of the group the
file is associated to
• The third set represents the permissions of the everyone elseThose sets are
composed by 3 values. rwx means that specific persona has read, write and
execution access. Anything that is removed is swapped with
– , which lets you form various combinations of values and relative
permissions: rw– , r––, r–x , and so on
chmod a+r filename #everyone can now read
chmod a+rw filename #everyone can now read and writ
chmod o–rwx filename #others (not the owner, not in
chmod og–r filename #other and group can't read any
You can change the permissions given to a file using the chmod
command.chmod can be used in 2 ways. The first is using symbolic arguments,
the second is using numeric arguments. Let's start with symbols first, which is
more intuitive.
You type chmod followed by a space, and a letter:
a stands for all
u stands for user
g stands for group
stands for others
Then you type either + or – to add a permission, or to remove it. Then you
enter one or more permissions symbols ( r , w , x ).
HUP means hang up. It's sent automatically when a terminal window that
started a process is closed before terminating the process.
INT means interrupt, and it sends the same signal used when we press ctrl–C in
the terminal, which usually terminates the process.
KILL is not sent to the process, but to the operating system kernel, which
immediately stops and terminates the process.
TERM means terminate. The process will receive it and terminate itself. It's
thedefault signal sent bykill.
CONT means continue. It can be used to resume a stopped process.
STOP is not sent to the process, but to the operating system kernel, which
immediately stops (but does not terminate) the process.
which will only work for executables stored on disk, not aliases or built-in shell
functions.
29)Vim :
vim is a very popular file editor, especially among programmers. It's actively
developed and frequently updated, and there's a very big community around
it. There's even a Vim conference!
vi in modern systems is just an alias to vim , which means vi i m proved.
You start it by running vion the command line.
30)Su :While you're logged in to the terminal shell with one user, you might
have the need to switch to another user.
For example you're logged in as root to perform some maintenance, but then
you want to switch to a user account.
3.
Control Statements
Features of DOS
MS-DOS (Microsoft Disk Operating System) is a foundational operating system
that provided the groundwork for many features and concepts used in modern
operating systems. While it's relatively simple compared to contemporary OSs
like Windows, macOS, or Linux, MS-DOS had several key features that made it
versatile and widely adopted during its heyday. Here are some of its notable
features:
Limitations of MS-DOS
Despite its significance in the history of computing, MS-DOS had several
limitations compared to modern operating systems. Here are some of the most
notable limitations of MS-DOS:
DOS Commands
DOS Commands are instructions that allow Windows users to conduct tasks on
files and folders. As you may know, a file is a container for a collection of
information or data, and a directory is a collection of files. These are case
insensitive.
The file name in MS-DOS is in 8dot format and broken into two parts - primary
and secondary names. The primary name can be up to eight characters long,
while the secondary name can be up to four characters with a dot. For
example, in the filename Logo.jpg, the primary name is Logo, while the
secondary name is .jpg. Secondary names are set for each type of file, so for
system files, the secondary name is .sys, and for text files, it is .txt, etc. Special
characters such as >, ., /, *, ?, |, & Space are not permitted in file or directory
names. Here is a list of the most common file types, along with their default
secondary names: