KEMBAR78
OS Lab File - Merged | PDF | Command Line Interface | Shell (Computing)
0% found this document useful (0 votes)
7 views49 pages

OS Lab File - Merged

The document outlines various shell commands, threading concepts, CPU scheduling algorithms, interprocess communication, and synchronization problems in operating systems, authored by Vaibhav Pacherwal. It also details the implementation of a Simple Shell application that allows users to execute commands in a command-line interface, including features like error handling and built-in commands. Additionally, it discusses deadlock detection and page replacement algorithms, providing a comprehensive overview of operating system principles and practices.

Uploaded by

priyanka07suri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views49 pages

OS Lab File - Merged

The document outlines various shell commands, threading concepts, CPU scheduling algorithms, interprocess communication, and synchronization problems in operating systems, authored by Vaibhav Pacherwal. It also details the implementation of a Simple Shell application that allows users to execute commands in a command-line interface, including features like error handling and built-in commands. Additionally, it discusses deadlock detection and page replacement algorithms, providing a comprehensive overview of operating system principles and practices.

Uploaded by

priyanka07suri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Shell Commands Assignment

Vaibhav Pacherwal 2023UCD2139

1. cd: Changes the current directory. It allows you to navigate between different
directories in your file system.
2. mkdir: Creates a new directory. This command is used to make a new folder in
the specified location.
3. dir: Lists files and directories in the current directory (commonly used in
Windows). It provides a view of the contents within a directory.
4. rmdir: Removes an empty directory. This command deletes a directory only if it
is empty.
5. echo: Displays a line of text or a variable value. It is often used to output text
to the terminal or to write text to a file.
6. del: Deletes one or more files (commonly used in Windows). This command is
used to remove files from the file system.
7. cls: Clears the screen (commonly used in Windows). It clears all the previous
commands and outputs from the terminal screen.
8. ping: Tests the reachability of a host on an IP network. It sends ICMP echo
requests to a specified host and measures the response time.

The implementations have been attached below


Process creation and termination for the
operating system ( fork, wait, signal etc.)

By- Vaibhav
Pacherwal
2023UCD2139
By- Vaibhav
Pacherwal
2023UCD2139
By- Vaibhav
Pacherwal
2023UCD2139
Threads Assignment
VAIBHAV PACHERWAL
2023UCD2139
● Multiple threading
● Implementing Thread using Runnable Interface as argument
CPU Scheduling Algorithms
Vaibhav Pacherwal
2023UCD2139
First Come First Serve : Processes don’t have any kind of priority biasing,
the processes which arrive can wait in the ready queue on FCFS basis.

Shortest Job First : If more than 1 processes are in the ready queue at a
point in time, they will be processed in increasing order of their burst time.

Round Robin : Ready queue is implemented as a circular one and processes


arrive in the queue in first come first serve fashion.
Priority : Processes are allotted a priority index
I⭲tgiPiocgss Commu⭲icatio⭲
Vaibhav Pacherwal

2023UCD2139
Signals and pipes are crucial for interprocess communication in operating systems. Signals are
used to notify processes of events, while pipes allow the transfer of data between processes.
They enable efficient and effective communication between different processes.
Critical Section Problem
Vaibhav Pacherwal
2023UCD2139

The critical section problem arises when multiple processes attempt to access shared
resources simultaneously, leading to inconsistencies and unpredictable behavior.
Proper synchronization mechanisms are essential to ensure data integrity and maintain
system stability in such scenarios.
Pioducei Consumei Pioblem

Readei Wiitei Pioblem

Dining Philosophei’s Pioblem

Bankei’s Algoiithm

Vaibhav Pacherwal

2023UCD2139

1) Producer – consumer problem, is a common paradigm for


cooperating processes. A producer process produces
information that is consumed by a consumer process. One
solution to the producer – consumer problem uses shared
memory. To allow producer and consumer processes to run
concurrently, there must be available a buffer of items that can
be filled by the producer and emptied by the consumer. This
buffer will reside in a region of memory that is shared by the
producer and consumer processes. A producer can produce
one item while the consumer is consuming another item. The
producer and consumer must be synchronized, so that the
consumer does not try to consume an item that has not yet
been produced.
2) A database is to be shared among several concurrent
processes. Some of these processes may want only to read
the database, whereas others may want to update (that is, to
read and write) the database. We distinguish between these
two types of processes by referring to the former as readers
and to the latter as writers. Obviously, if two readers access
the shared data simultaneously, no adverse effects will result.
However, if a writer and some other thread (either a reader or
a writer) access the database simultaneously, chaos may
ensue. To ensure that these difficulties do not arise, we
require that the writers have exclusive access to the shared
database. This synchronization problem is referred to as the
readers – writer’s problem.
3) The dining philosophers problem is a classic
synchronization issue, exemplifying a broader class of
concurrency-control problems. It illustrates the need to
allocate resources among processes in a deadlock-free and
starvation-free manner. Imagine five philosophers who spend
their lives thinking and eating. They share a circular table with
five chairs, one for each philosopher. In the center is a bowl of
rice and five chopsticks. While thinking, a philosopher does
not interact with others. When hungry, she tries to pick up the
two chopsticks closest to her, but can only pick up one at a
time and cannot take one already held by a neighbor. Once a
hungry philosopher has both chopsticks, she eats without
putting them down. After eating, she places the chopsticks
down and resumes thinking. This problem can lead to
deadlock, so rules must be established to prevent it.

4) Deadlock Detection is an important task of OS. As the OS


doesn’t take many precautionary means to avoid it. The OS
periodically checks if there is any existing deadlock in the
system and takes measures to remove the deadlocks. For
that, Bankers’ Algorithm plays a vital role.
DEADLOCK DETECTION(BANKERS)

PAGE REPLACEMENT ALGORITHMS


Vaibhav Pacherwal
2023UCD2139
1) The Banker's Algorithm prevents deadlock by simulating
resource allocation. It checks if a system can safely allocate
resources without causing a deadlock. If a safe sequence exists,
allocation proceeds; otherwise, it waits, ensuring resources are
allocated only when the system remains in a safe state.
2) Page Fault: A page fault occurs when a program tries to
access a page not currently in memory, triggering a
system interrupt to load the required page from disk.
Page Replacement Algorithms
1. FIFO : Replaces the oldest page in memory. Simple to
implement but may not be optimal, leading to high page
fault rates.
2. LRU : Replaces the least recently accessed page,
aiming to keep frequently used pages in memory. More
efficient but requires tracking page access history.
3. Optimal : Replaces the page that won’t be used for the
longest time in the future. Provides the best performance
but is impractical due to future knowledge requirements.
4. LRU Approximation : Uses reference bits to
approximate LRU behavior. Pages are periodically
scanned; if referenced, they’re given a second chance.
This balances efficiency and implementation complexity,
providing a reasonable estimate of recency without full
tracking.
File Operations in OS
Vaibhav Pacherwal
2023UCD2139

Various File System calls in Windows OS are open, append, read


close etc.
Disk Scheduling Algorithms
1. FCFS:
2. SSTF:
3. CSCAN:
4. SCAN
5. LOOK
4. CLOOK:
OPERATING SYSTEM
PROJECT FILE

Submitted by:-Vaibhav Pacherwal


2023UCD2139
PROJECT: SIMPLE SHELL

This project implements a Simple Shell application that allows


users to interact with the operating system via a command-line
interface (CLI), similar to the functionality of the Windows
Command Prompt or a UNIX Shell. The shell executes standard
system commands, handles built-in commands such as cd (change
directory), exit, and runs external programs.

Objective:

The main goal of this project is to create a basic shell environment


that:

• Accepts user input in the form of commands.


• Executes standard system commands (like mkdir, dir, ls, etc.).
• Implements built-in commands (exit, cd).
• Provides feedback to the user when the command is executed or
if an error occurs.

Features:

The Simple Shell should support the following features:

1. Command Prompt:
• Displays a prompt (simple_shell> ) to allow user input.
2. Command Execution:
• Executes external commands (e.g., mkdir, ls, dir) by calling
system functions or external processes.
3. Built-in Commands:
• exit: Exits the shell.
• cd <directory>: Changes the current directory to the
specified directory.

4. Error Handling:
• Provides error messages when invalid commands are entered
or if execution fails.
5. Infinite Loop:
• The shell keeps running until the user types exit.
6. User-Friendly CLI:
• The shell prompts the user for input, displays the results of
commands, and handles common user errors gracefully.

Technologies Used:
• Programming Language: C language for implementation.
• System Calls: system() for running external commands.
• Libraries/Modules Used:
o stdio.h: Standard input/output functions.
o stdlib.h: For memory allocation and command execution
(system()).
o string.h: For string manipulation (strcmp, strcspn).
o unistd.h (optional): For system-level operations on UNIX
systems, such as chdir().
Implementation Code

Compiling the code:


Testing with Simple Commands:
The simple shell application closes automatically when the user
enters ‘exit’ command.
Conclusion

In this project, I have successfully developed a basic Simple Shell


application that mimics the behaviour of a command-line interface
(CLI), similar to the Windows Command Prompt or UNIX shell. The
primary goal was to create a user-friendly environment where the
user can execute standard system commands and interact with the
operating system.

References

• GNU C Library Documentation


• Bash Manual
• Windows API Documentation
• Operating System concepts by silberschatz galvin gagne

You might also like