OS mod 1(8m)
OS mod 1(8m)
o Program execution
o Control Input/output devices
o Program creation
o Error Handling
o Accounting
o Security and Protection
o File Management
o Communication
Program Execution:
Program Creation
The Operating system offers the structures and tools, including editors and
debuggers, to help the programmer create, modify, and debugging programs.
Error Handling:
The Operating System also handles the error occurring in the CPU, in Input-
Output devices. It fixes the errors and also prevents the process from coming
to a deadlock. It also looks for any type of error or bugs that can occur while
any task.
While working with computers, errors may occur quite often. Errors may occur
in the:
o Input/ Output devices: For example, connection failure in the network,
lack of paper in the printer, etc.
o User program: For example: attempt to access illegal memory locations,
divide by zero, use too much CPU time, etc.
o Memory hardware: For example, Memory error, the memory becomes
full, etc.
To handle these errors and other types of possible errors, the operating system
takes appropriate action and generates messages to ensure correct and consistent
computing.
File management
For file management, the operating system must know the types of different
files and the characteristics of different storage devices. It has to offer the
proportion and safety mechanism of documents additionally.
It is the simplest Operating System Structure and is not well defined; It can
only be used for small and limited systems. In this structure, the interfaces and
levels of functionality are well separated;
Layered Approach
Micro-kernel
There are commonly five types of system calls. These are as follows:
1. Process Control
2. File Management
3. Device Management
4. Information Maintenance
5. Communication
Process Control
Process control is the system call that is used to direct the processes. Some
process control examples include creating, load, abort, end, execute, process,
terminate the process, etc.
File Management
File management is a system call that is used to handle the files. Some file
management examples include creating files, delete files, open, close, read,
write, etc.
Device Management
Device management is a system call that is used to deal with devices. Some
examples of device management include read, device, write, get device
attributes, release device, etc.
Information Maintenance
Communication
Communication is a system call that is used for communication. There are some
examples of communication, including create, delete communication
connections, send, receive messages, etc.
There are various examples of Windows and Unix system calls. These are as
listed below in the table:
Process Windows Unix
Ans: Concurrency:
Concurrency relates to an application that is processing more than one task at
the same time. Concurrency is an approach that is used for decreasing the
response time of the system by using the single processing unit.
Parallelism:
Parallelism is related to an application where tasks are divided into smaller sub-
tasks that are processed seemingly simultaneously or parallel.
It enables single sequential CPUs to do lot of things “seemingly”
simultaneously.
S.N
O Concurrency Parallelism
1. Explain about the following commands Sudo, su, sudo, cat, man,
ls, kill, ps, top, more, less, head, tail, info
6. **ls**: "ls" stands for "list" and is used to list files and directories
in a directory. It displays the names of files and directories in the
specified location, allowing you to see what files and directories are
present.
11. **less**: "less" is similar to "more" and is also used to view file
contents. However, it provides more advanced features like backward
scrolling, searching, and navigation within the file.
12. **head**: "head" is used to display the first few lines of a file. By
default, it displays the first 10 lines, but you can specify a different
number using the "-n" option.
13. **tail**: "tail" is used to display the last few lines of a file. By
default, it displays the last 10 lines, but you can specify a different
number using the "-n" option.
14. **info**: "info" is a command used to view the documentation
for a command or system function in the GNU Info format. It provides
more detailed and structured information compared to the
traditional man pages.
4. What is the purpose of ssh command and write the steps for
this process
The ssh command is used to establish a secure and encrypted connection to a
remote server or device over a network. It allows you to log in to and execute
commands on the remote system securely.
Here are the steps involved in using the ssh command:
1. Check for SSH: Ensure that the remote server you want to connect to has
SSH installed and running. Most Linux distributions have SSH pre-
installed, but if not, you may need to install the SSH server software.
2. Open Terminal: Open the terminal or command prompt on your local
machine from which you want to initiate the SSH connection.
3. SSH Syntax: The basic syntax of the ssh command is as follows:
ssh [options] [username@]hostname
[options]: Specifies additional options for the SSH connection. For
example, you can use -p to specify a different port number if the SSH
server is running on a non-standard port.
[username@]hostname: Specifies the username and hostname or IP
address of the remote server you want to connect to.
4. Connect to Remote Server: Use the ssh command with the appropriate
options and the target server's details to initiate the connection. For example:
ssh username@hostname
Replace username with your username on the remote server, and hostname
with the hostname or IP address of the remote server.
MODULE – 3
8marks
1) a) Explain the file Hierarchy system with diagram.
Ans:
The file hierarchy system, also known as the file system hierarchy or
directory structure, is a way of organizing files and directories on a
computer's storage system.
It provides a logical structure that helps users and operating systems
locate and manage files efficiently.
The file hierarchy system is typically represented as a tree-like structure,
where each node in the tree represents a directory (also known as a
folder) and each leaf node represents a file.
Directories can contain both files and subdirectories, creating a
hierarchical organization.
At the top of the hierarchy is the root directory, denoted by a forward
slash (/) in Unix-based systems or a drive letter (such as C:\) in Windows
systems.
All other directories and files are organized beneath the root directory.
This hierarchical arrangement allows for easy navigation and
organization of files and directories on a computer system.
Users and operating systems can traverse the file hierarchy by specifying
the appropriate directory paths to locate and access files.
2. Symbolic Notation:
- Each permission is represented by a symbol:
- Read (r)
- Write (w)
- Execute (x)
- The syntax for symbolic notation is:
```
chmod [who][operator][permissions] file
```
- Who can be one of the following:
- u: Owner
- g: Group
- o: Others
- a: All (u+g+o)
- Operator can be one of the following:
- +: Add permissions
- -: Remove permissions
- =: Set permissions explicitly
- Permissions are represented by the symbols (r, w, x).
- Example:
```
chmod u=rw,g=rx,o=r myfile.txt
```
- The owner has read and write permissions.
- The group has read and execute permissions.
- Others have read permission.
5) Explain about the various types of file systems that are used for
various operating systems.
Ans:
Different operating systems use various file systems to manage and organize
data on storage devices. Here's an overview of some commonly used file
systems for different operating systems:
1. Windows:
- NTFS (New Technology File System): NTFS is the primary file system used by
modern versions of Windows, including Windows 10. It provides advanced
features such as file and folder permissions, encryption, compression, and
support for large file sizes and volumes.
- FAT/FAT32 (File Allocation Table): FAT and FAT32 are older file systems that
are still used for compatibility reasons. They have limited features compared to
NTFS but are supported by various operating systems and devices.
2. macOS:
- APFS (Apple File System): APFS is the default file system introduced in
macOS High Sierra. It is optimized for solid-state drives (SSDs) and provides
features like encryption, snapshotting, and efficient storage management.
- HFS+ (Hierarchical File System Plus): HFS+ was the primary file system used
by macOS before the introduction of APFS. It supports features like journaling,
file and folder permissions, and case-insensitive and case-sensitive file names.
3. Linux:
- ext4 (Fourth Extended File System): ext4 is the most widely used file system
in Linux. It is an improvement over its predecessor, ext3, and provides features
such as journaling, large file and volume support, and backward compatibility
with ext2.
- Btrfs (B-Tree File System): Btrfs is a modern copy-on-write file system
designed for Linux. It offers features like scalability, snapshots, checksums, and
RAID-like functionality.
- XFS (XFS File System): XFS is a high-performance file system known for its
scalability and reliability. It supports large file sizes, extensive parallelism, and
features like journaling and online defragmentation.
4. Unix and Unix-like Systems:
- UFS (Unix File System): UFS is the traditional file system used by many Unix-
based operating systems. It provides features like file and directory
permissions, journaling, and support for symbolic links.
- ZFS (Zettabyte File System): ZFS is a robust and scalable file system used in
Unix-like systems. It offers advanced features such as data integrity, data
compression, snapshotting, and storage pool management.
These are just a few examples of file systems used in different operating
systems. Each file system has its own advantages and may be optimized
for specific requirements like performance, reliability, scalability, or
compatibility. The choice of file system depends on the specific needs of
the operating system, storage device, and intended use cases.
MODULE 4(8M)
Vim stands for "Vi Improved", and it is an enhanced version of the Vi editor
that was developed in the 1970s as part of the Unix operating system. Vim is
designed to be a modal editor, which means that it has different modes for
navigating and editing text.
In Vim, you can navigate and edit text using the keyboard, without needing to
use a mouse or other pointing device. Vim has a wide range of features and
commands, and it can be customized extensively to suit the needs of individual
users.
Features of Vim
To create a Vim file and perform searching and substituting on a particular part
of the text, you can follow these steps:
1. Open the Vim editor by running the command vim in your terminal.
2. To create a new file, press the i key to enter the Insert mode. Now you
can start typing your text.
3. Enter the desired text, including the part where you want to perform the
search and substitution.
4. To save the file, press the Esc key to exit Insert mode. Then type :wq
and press Enter. This command writes the changes to the file and quits
Vim.
5. Now let's perform searching and substituting on the specific part of the
text. Open the file again by running vim <filename> in the terminal,
replacing <filename> with the name of the file you created.
6. Once the file is open in Vim, press the Esc key to ensure you are in the
Normal mode.
7. Move the cursor to the part of the text where you want to perform the
search and substitution.
8. Press the : key to enter Command-line mode.
9. To search for a specific pattern, type / followed by the pattern you want
to search for. For example, if you want to search for the word "example",
you would type /example.
10.Press Enter to perform the search. Vim will highlight the first occurrence
of the pattern in the text.
11.To substitute the searched pattern with a different text, type
:s/old_text/new_text/, replacing old_text with the pattern
you searched for and new_text with the replacement text. For example,
if you want to replace "example" with "replacement", you would type
:s/example/replacement/.
12.To perform the substitution on the current line, press Enter. If you want to
perform the substitution globally (on all occurrences of the pattern in the
file), add the g flag at the end of the command. For example,
:s/example/replacement/g.
13.Vim will perform the substitution and provide feedback on the number of
substitutions made.
14.You can use the n key to move to the next occurrence of the pattern and
perform the substitution again if needed.
15.Once you are done with the search and substitution, you can save the
changes and quit Vim by pressing the Esc key, then typing :wq and
pressing Enter.
- `0` (zero): Move the cursor to the beginning of the current line.
H, M, L - These keys are used to move the cursor to the top, middle, and
bottom of the screen, respectively. The H key moves the cursor to the top of the
screen, the M key moves the cursor to the middle of the screen, and the L key
moves the cursor to the bottom of the screen.
Ctrl+f, Ctrl+b - These keys are used to move the cursor forward and backward
by a full screen, respectively. The Ctrl+f key moves the cursor forward by a full
screen, while the Ctrl+b key moves the cursor backward by a full screen.
Deletion Commands:
- `dw`: Deletes from the cursor to the end of the current word.
In Vim, buffers are an essential concept for managing multiple files or text
sources within the editor. A buffer represents the content of a file or a text
source that is currently open in Vim. Understanding buffers allows you to work
with multiple files simultaneously and switch between them efficiently. Here
are the key concepts related to buffers in Vim:
1. What is a shell, shell script, what are the different types of shells ?
In computing, a shell is a program that provides an interface between the
user and the operating system. It allows users to interact with the
computer by typing commands and executing them. The shell interprets
the commands entered by the user and communicates with the operating
system to carry out the requested tasks.
A shell script is a script or program written in a shell language, which is
interpreted and executed by a shell. Shell scripts can automate repetitive
tasks, execute a series of commands, manipulate files and directories,
and perform various other tasks. They are commonly used for system
administration, batch processing, and automation.
There are several different types of shells available, with some of the most
popular ones being:
1. Bash (Bourne Again SHell): Bash is the default shell for most Linux
distributions and is widely used on Unix-based systems. It is a powerful
and feature-rich shell, compatible with the original Bourne shell (sh) and
includes additional functionality.
2. sh (Bourne Shell): The Bourne shell was one of the first Unix shells and is
still available on many Unix-like systems. It is a relatively simple shell and
lacks some of the advanced features found in newer shells.
3. csh (C Shell): The C shell provides a C-like syntax and includes features
like command-line history and job control. It was popular in the early days
of Unix but has been largely replaced by more modern shells.
4. tcsh (TENEX C Shell): The tcsh is an enhanced version of the C shell,
adding additional features such as command completion and improved
command-line editing capabilities.
5. Korn Shell (ksh): The Korn shell is an advanced shell that combines
features from the Bourne shell (sh) and the C shell (csh). It offers a rich
set of features, including advanced scripting capabilities.
6. PowerShell: While not a traditional Unix shell, PowerShell is a powerful
shell and scripting language developed by Microsoft for Windows. It
provides access to system administration tasks and automation on
Windows-based systems.
These are just a few examples of the many shells available. Different
operating systems may have their own default shells, and users can often
choose which shell they prefer to use based on their needs and
preferences.
To call the function, we simply write its name followed by the argument(s)
we want to pass. In this case, we call greet twice, passing "Alice" and "Bob"
as arguments. When the function is called, it executes the code inside its
block, which results in the greeting message being displayed for each name.
#!/bin/bash
In this example, the add function takes two arguments and calculates their
sum. The local keyword is used to declare a local variable called result,
which stores the sum. Then, the function echoes the value of result,
effectively returning it.
When we call the add function with the arguments 5 and 3, the return value
is assigned to the variable sum. Finally, we display the result using the echo
command.
The sum is: 8
This is a basic example of how functions work in shell scripting. You can
create more complex functions with multiple arguments, use control
structures inside functions, and even call other functions from within a
function. Functions provide a way to structure and organize your code,
making it more readable and maintainable.
If-else statement
case-sac statement
1. If-else statement
If else statement is a conditional statement. It can be used to execute
two different codes based on whether the given condition is satisfied or
not. There are a couple of varieties present within the if-else statement.
They are –
a) if-fi
b) if-else-fi
c) if-elif-else-fi
d) nested if-else
a. if [ expression ]; then
statements
fi
b. if [ expression ]
then
statement1
else
statement2
fi
c. if [ expression1 ]
then
statement1
statement2
.
.
elif [ expression2 ]
then
statement3
statement4
.
.
else
statement5
fi
case $var in
Pattern 1) Statement 1;;
Pattern n) Statement n;;
Esac
Name="Satyajit"
case "$Name" in
#case 1
"Rajib") echo "Profession : Software Engineer" ;;
#case 2
"Vikas") echo "Profession : Web Developer" ;;
#case 3
"Satyajit") echo "Profession : Technical Content Writer" ;;
Esac
Output:
Profession : Technical Content Writer
In this example, the for loop iterates over a range of numbers from 1
to 5. In each iteration, the value of i is assigned to the current number
in the range, and the code block within the loop is executed. The echo
command displays the message "Number: " followed by the value of
i. When you run this script, the output will be:
Output:
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
2. While loop:
#!/bin/bash
In this example, the while loop iterates until the value of the counter
variable is less than or equal to 5. In each iteration, the code block
within the loop is executed. The echo command displays the message
"Count: " followed by the value of counter. After each iteration, the
counter variable is incremented by 1 using the $(( )) syntax. When the
value of counter becomes 6, the condition becomes false, and the
loop terminates. When you run this script, the output will be:
Output:
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
PROCESS:
A process is an active program i.e a program that is under execution. It is more than the program
code as it includes the program counter, process stack, registers, program code etc. Compared to
this, the program code is only the text section.
A program is not a process by itself as the program is a passive entity, such as file contents, while the
process is an active entity containing program counter, resources etc.
New - The process is in the new state when it has just been created.
Ready - The process is waiting to be assigned the processor by the short-term scheduler.
Waiting - The process is waiting for some event such as I/O to occur.
THREAD:
Within a program, a Thread is a separate execution path. It is a lightweight process that the operating
system can schedule and run concurrently with other threads. The operating system creates and
manages threads, and they share the same memory and resources as the program that created
them. This enables multiple threads to collaborate and work efficiently within a single program.
TYPES OF THREADS:
A process control block is associated with each of the processes. It contains important information
Process State - This specifies the process state i.e. new, ready, running, waiting or terminated.
Program Counter - This contains the address of the next instruction that needs to be executed in the
process.
Registers - This specifies 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.
Scheduling queues, also known as process queues or job queues, are data
structures used in operating systems to manage the execution of multiple
processes. These queues help in organizing and prioritizing processes for
the CPU to execute. Here is a brief explanation along with a simple
diagram:
1. Ready Queue: This queue holds all the processes that are ready to
be executed by the CPU. Processes in the ready queue are waiting
for their turn to run and are typically organized based on their
priority. Higher priority processes usually get scheduled first.
2. Waiting Queue: This queue holds processes that are waiting for
certain resources or events to occur. For example, a process waiting
for user input or for a file to be loaded will be placed in the waiting
queue until the required resource becomes available.
3. Blocked Queue: This queue holds processes that are blocked or
suspended due to some external conditions. Processes in this queue
cannot proceed until the condition is satisfied. For instance, a
process waiting for I/O operations to complete or waiting for a
semaphore signal will be placed in the blocked queue.
4. Job Queue: This queue contains all the processes residing in the
system, including those that are waiting to be executed, running, or
suspended. It represents the total set of processes in the system.
n this diagram, the job queue encompasses all processes in the system.
The ready queue represents processes that are ready for execution, with
higher priority processes closer to the CPU. The waiting queue holds
processes waiting for resources, and the blocked queue holds processes
that are temporarily unable to proceed.
3. Define IPC and explain about the two models of IPC (Shared memory and
Message passing)
Both models have their advantages and are used in different scenarios.
The choice between shared memory and message passing depends on
factors such as the nature of the problem, the amount of data to be
exchanged, the level of synchronization required, and the programming
paradigm being used.
Differences:
1. Control Flow: Cooperative processes yield the CPU explicitly, while
independent processes execute without explicit coordination or
yielding.
2. Mutual Dependency: Cooperative processes often depend on each
other for resource sharing or synchronization, whereas independent
processes operate in isolation and do not rely on other processes.
3. Responsiveness vs. Isolation: Cooperative processes prioritize
system responsiveness and require responsible behavior from each
process, while independent processes prioritize process isolation
and allow processes to execute independently without coordination.
CPU Utilization Utilizes only a single CPU core Can utilize multiple CPU cores
Complexity Simpler to design and debug More complex to design and debug
6. Explain about the critical section problem and what are the three
requirements to build a solution for critical section problem
Utilization of Higher CPU utilization due to more Lower CPU utilization as processes may
CPU efficient allocation of CPU time. hold the CPU for longer durations.
Better support for real-time May not provide robust support for real-
Real-Time applications as higher-priority time applications as higher-priority tasks
Applications tasks can interrupt lower-priority may have to wait for lower-priority tasks
Support tasks. to complete.
MODULE – 7
8marks
1) Explain the characteristics of deadlock? Explain its prevention
and avoidance measures?
Ans:
Deadlock is a situation in concurrent computing where two or more
processes or threads are unable to proceed because each is waiting for a
resource that is held by another process or thread in the same set.
Deadlock arises when there is a circular dependency among processes,
each holding resources and waiting for resources held by others,
resulting in a standstill.
Characteristics of Deadlock:
1. Mutual Exclusion: At least one resource must be held in a non-sharable
mode, meaning only one process can access it at a time.
2. Hold and Wait: Processes holding resources may request additional
resources while still retaining the resources they currently hold.
3. No Preemption: Resources cannot be forcibly taken away from a process;
they can only be released voluntarily by the process.
4. Circular Wait: There exists a circular chain of two or more processes, where
each process is waiting for a resource held by another process in the chain.
Prevention of Deadlock:
1. Mutual Exclusion Prevention: Deadlock can be prevented by eliminating the
mutual exclusion requirement. However, this is not always feasible since
certain resources, such as printers or disks, are inherently non-sharable.
2. Hold and Wait Prevention: One approach is to enforce a rule where a
process must request and acquire all required resources before execution
begins, eliminating the hold and wait condition. However, this can lead to low
resource utilization and potential delays.
5) Process Need
A B C
P1 7 4 3
P2 1 2 2
P3 6 0 0
P4 0 1 1
P5 4 3 1
Apply Bankers Algorithm and Determine if the system is safe or not.
Also find safe state and safe sequence .
Ans:
6) Explain the concept of paging and segmentation and compare
them.
Ans:
Paging and segmentation are two memory management techniques used in
computer operating systems to manage the allocation of memory to processes.
1. Paging:
Paging divides the physical memory into fixed-size blocks called "pages,"
typically 4KB or 8KB in size. The logical memory is also divided into fixed-size
blocks called "page frames," which are the same size as the physical pages. The
main idea behind paging is to map these logical page frames to physical
memory frames.
Key features of paging:
- Each process's logical address space is divided into fixed-size pages.
- The physical memory is divided into fixed-size frames.
- The page table maintains the mapping between logical pages and physical
frames.
- Page tables are used to translate logical addresses to physical addresses
during memory access.
2. Segmentation:
Segmentation divides the logical memory into variable-sized segments, where
each segment represents a logical unit of the program, such as code, data,
stack, etc. Segments can vary in size, depending on the needs of the program.
Key features of segmentation:
- Logical memory is divided into variable-sized segments.
- Each segment represents a logical unit (e.g., code, data).
- Segments can have different sizes, reflecting the varying memory
requirements.
- Segmentation requires a segment table to map logical addresses to physical
addresses.
Comparison between paging and segmentation:
1. Memory Division:
- Paging: Physical memory and logical memory are divided into fixed-size pages
and page frames, respectively.
- Segmentation: Logical memory is divided into variable-sized segments.
2. Unit of Allocation:
- Paging: Memory allocation is done in fixed-size pages.
- Segmentation: Memory allocation is done in variable-sized segments.
3. Address Translation:
- Paging: Translation of logical addresses to physical addresses is done through
the page table.
- Segmentation: Translation of logical addresses to physical addresses is done
through the segment table.
4. Fragmentation:
- Paging: Internal fragmentation may occur due to fixed-size pages.
- Segmentation: External fragmentation may occur due to variable-sized
segments.
5. Memory Allocation Flexibility:
- Paging: Less flexible, as memory is allocated in fixed-size pages.
- Segmentation: More flexible, as memory is allocated in variable-sized
segments.
6. Address Space Sharing:
- Paging: Limited or no sharing of memory between processes.
- Segmentation: Facilitates sharing of segments between multiple processes.