0% found this document useful (0 votes)
47 views8 pages

Operating Systems Lab Assignments Guide

This document outlines 11 lab assignments for an Operating Systems course. The assignments cover topics like Linux commands, shell scripting, process management using fork() and wait(), CPU scheduling algorithms, memory management strategies, disk scheduling algorithms, and concepts of threads and inter-process communication. Students will implement programs and simulations in languages like C/C++/Java to demonstrate scheduling policies, memory allocation techniques, and IPC methods.

Uploaded by

Kumar Shresth
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)
47 views8 pages

Operating Systems Lab Assignments Guide

This document outlines 11 lab assignments for an Operating Systems course. The assignments cover topics like Linux commands, shell scripting, process management using fork() and wait(), CPU scheduling algorithms, memory management strategies, disk scheduling algorithms, and concepts of threads and inter-process communication. Students will implement programs and simulations in languages like C/C++/Java to demonstrate scheduling policies, memory allocation techniques, and IPC methods.

Uploaded by

Kumar Shresth
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

LAB Assignment 1

Operating Systems (UCS-303)

Instructions: The instructor is required to discuss the following questions and commands
with the students. Students are required to make note on these.

1. Introduction to the operating system with key functions.


2. Introduction to the Unix/Linux (Architecture).
3. Concept of Shell.
4. Types of Shell.
5. Command structure.
6. Introduction of basic linux commands (sudo, ls, pwd, mkdir, rmdir, rm, cd, cp, wc,
mv, cmp, passwd, who, uname)
7. install, update, upgrade and remove any package in linux (apt-get).
8. >, >> option for directing the output of a command.
9. cat command.
10. Compressing and archiving files (zip, tar)

Self-Study: Perform a case study by installing and exploring various types of operating systems
on a physical or logical (virtual) machine. (Linux Installation): This is highly recommended
that you should take backup of your entire data before start with the installation process.
Reference Link: [Link]
windows-10-using-virtualbox/
LAB Assignment 2
Operating Systems (UCS-303)

Instructions: The instructor is required to discuss the following questions and commands
with the students. Students are required to make note on these.

1. Introduction of internal and external commands.


2. Feeding output of one command to another command by pipelining.
3. expr, locating command.
4. echo command.
5. Using . and ..
6. Ways for signing off from linux.
7. Ping, Man and help command.
8. Combining the commands.
9. File permissions and changing the access rights (chmod).
10. vi editor and its basics: write a small paragraph using vi editor.

Self study :

1. grep, sort, ps command


2. Read Basics of shell programming.
Shell Programming
1. A shell program is nothing but a series of unix commands.
2. Instead of specifying one job at a time, the shell is given a to-do-list of a program that
carries out an entire procedure.
3. Such programs are known as shell scripts.
4. Shell programming language incorporates most of the features that most modern day
programming languages offer.

Shell variables – Rules for building shell variables are as follows:

1. A variable name is any combination of alphabets, digits and an underscore (‘_’).


2. No commas or blanks are allowed within a variable name.
3. The first character of a variable name must either be an alphabet or an underscore.
4. Variable names should be of any reasonable length.
5. Variable names are case sensitive.

Input/Output

1. Keywords for accepting input – read


2. Displaying output – echo

Assigning value to variables –

1. Values can be assigned to variables through read statement or also by using a simple
assignment operator. For ex: age=30

Note : While assigning values to variables using assignment operator, no spaces to be given
on either side of it. If the variable doesn’t exist it will be created and value assigned

Note : To print or access value of a variable use ‘$’ .

For ex: To print value of variable ‘flag‘ write - echo $flag

Arithmetic in Shell script -

1. All shell variables are string variables, hence to carry out arithmetic operations use
expr command which evaluates arithmetic expressions.
2. More than one assignment can be done in a single statement.
3. Before and at the end of expr keyword use ` (back quote) sign not the (single quote
i.e.') sign which is generally above TAB key.
4. Terms of the expression provided to expr must be separated by blanks. Thus
expression expr 10+20 is invalid.
5. The ‘*” symbol must be preceded by a \ ,otherwise the shell treats it as a wildcard
character for all files in the current directory.

OPERATORS USED IN SHELL SCRIPT – OPERATOR MEANING

1. –gt Greater than


2. –lt Less than
3. –ge Greater than or equal to
4. –le Less than or equal to
5. –ne Not equal to
6. –eq Equal to
7. –a Logical AND
8. –o Logical OR
9. ! Logical NOT

CONTROL INSTRUCTIONS IN SHELLS –

There are four types of control instructions in shell :

1. Sequence Control Instruction.


2. Selection or Decision Control Instruction
3. Repetition or Loop control Instruction
4. Case Control Instruction

Decision statements –

If-then-else-fi statements:

if condition then Commands else Commands fi

For statements:

for control variable in value1 value 2 value3 do

Command list done

While statements:

while control command do


Command list Done

Until statements:

until control command do

Command list done

Case statements:-

case value in

choice 1) commands;;

choice 2) commands;;

esac

Steps to write and execute a script

1. Open the terminal. Go to the directory where you want to create your script.

2. Create a file with . sh extension.

3. Write the script in the file using an editor.

4. Make the script executable with command chmod +x <fileName>.

5. Run the script using ./<fileName>.


LAB Assignment 3
Operating Systems (UCS-303)

Instructions: The instructor is required to discuss the basic syntax of shell programming;
students have to implement following programs using shell script.

1. Write a shell program to add two numbers.


2. Write a shell program to compare two strings using command prompt.
3. Write a shell program to generate Fibonacci series.
4. Write a shell program to check whether a character is VOWEL or CONSONANT
using switch.
5. Write a shell program to display total number of words and and total number of lines
in a file.
6. Create a script that takes a file name as input and makes a backup copy of the file with
a timestamp appended to the filename.
7. A script that takes a filename as input and displays information about the file, such as
its size, permissions, owner, and modification time.
8. Create a script that displays information about the system, such as the OS version,
CPU, memory, disk usage, and network details.
LAB Assignment 4
Operating Systems (UCS-303)
Instructions: The instructor is required to discuss the concept of system call; students have
to implement following system calls related to process and file management.

1. Write a program to implement fork () system call.


2. Write a program to implement Wait () and Exit () System Calls
3. Write a program to implement the system calls open (), read (), write () & close ().

LAB Assignment 5
Operating Systems (UCS-303)

Write a program using C/C++/Java to simulate the FCFS, SJF (pre-emptive as well as non-
preemptive approach), priority scheduling and RR, CPU scheduling algorithms. The scenario
is: user may input n processes with respective CPU burst time and arrival time (also take the
priority number in case of priority scheduling). System will ask the user to select the type of
algorithm from the list mentioned above. System should display the waiting time for each
process, average waiting time for whole system, and final execution sequence.

LAB Assignment 6
Operating Systems (UCS-303)

Write a program in C/C++/Java to simulate the Banker’s algorithm for deadlock avoidance.
Consider at least 3 processes in the system, with 4 resource classes having at least one
resource instance for each class. Assume the values for Available, Allocation, MAX, and
request from particular process from your side. Program must reflect for two cases, where
safe sequence exists for one and safe sequence does not exist for another.
LAB Assignment 7
Operating Systems (UCS-303)
Instructions: The instructor is required to discuss the concept of Thread and IPC; students
have to implement following.

1. Write C programs to demonstrate various thread related concepts.


2. Producer-Consumer Problem using Semaphores and Reader Writer Problem.
3. Write C programs to simulate Intra & Inter – Process Communication (IPC)
techniques: Pipes, Messages, Queues and Shared Memory.

LAB Assignment 8
Operating Systems (UCS-303)
Write a program using C/C++/Java to simulate the first fit, best fit and worst fit memory
allocation strategy. Assume memory chunk and initial requirement for memory block from
your side.

LAB Assignment 9
Operating Systems (UCS-303)
Simulate page replacement algorithms: FIFO, LRU and Optimal

LAB Assignment 10
Operating Systems (UCS-303)
Implementation of Disk Scheduling using FCFS and SSTF algorithm.

LAB Assignment 11
Operating Systems (UCS-303)
Implementation of Disk Scheduling using FCFS, SCAN and C-SCAN algorithm

Common questions

Powered by AI

Pipelining and redirection enhance Unix/Linux command line functionality by enabling sequential and redirected data processing. Pipelining (using |) allows the output of one command to be directly used as the input to another, facilitating efficient data processing without interim files, such as 'ps aux | grep init'. Redirection modifies standard I/O flows, where '>' directs output to files, and '<' takes file content as input for commands, enhancing command flexibility and enabling automation in tasks such as logging or batch processing .

Shell variables differ from traditional programming languages in several ways. They are primarily string variables and do not support complex data types like integers or floats directly, requiring commands like 'expr' for arithmetic operations. Variable naming rules are stricter; they must start with an alphabet or underscore and are case-sensitive. These restrictions mean shell scripting may be more cumbersome for detailed logic or arithmetic-heavy scripts, necessitating careful handling of data types and syntax when developing scripts .

Shell scripts serve as powerful tools in Unix/Linux for automating and managing complex administrative tasks by chaining together multiple commands and scripting logic. They allow for automation of repetitive tasks, such as backups, system updates, and monitoring, improving efficiency and reducing human error. Scripts can incorporate control structures like conditionals and loops, enhancing their capabilities far beyond individual command execution. This automation capability makes shell scripts invaluable for system administrators managing complex environments .

The Banker’s algorithm ensures deadlock avoidance by simulating the allocation of resources to processes and only proceeding if it results in a safe state. It maintains matrices for maximum resource demand and current allocations, assessing requests against available resources. If granting a request leads to all processes completing in some sequence, it is considered safe. However, this algorithm's limitations include the need for prior knowledge of maximum resource demands, potentially high computational overhead, and assumptions about consistent process behavior that can be unrealistic in dynamic, unpredictable environments .

The system call fork() creates a new process by duplicating an existing one, essential for multitasking. It returns a process ID, allowing parent and child processes to be differentiated. The wait() system call is used by parent processes to wait for state changes in child processes, effectively synchronizing process termination. The exit() system call terminates a process, returning a status to the parent, which can be retrieved by wait(). Together, these calls allow for robust process management, enabling multiple processes to run concurrently while managing dependencies and resource deallocation .

Misconfigured file permissions in Linux can lead to unauthorized data access, data loss, and security vulnerabilities, as improper settings can allow users to read, write, or execute files they should not have access to. Mitigation involves using the chmod command to set appropriate read, write, and execute permissions for the owner, group, and others. Administrators should carefully audit file permissions, employing the principle of least privilege to limit access rights, thus enhancing security and preventing accidental or malicious access .

Page replacement algorithms enhance memory management by determining which pages to swap in and out of physical memory. FIFO (First-In, First-Out) is easy to implement but can suffer from Belady's anomaly, where increasing page frames results in more page faults. LRU (Least Recently Used) uses historical usage data to improve efficiency but requires additional hardware support or complex algorithms for tracking page usage. The Optimal algorithm minimizes page faults by predicting future requests, it's feasible only in theoretical scenarios due to the need for future knowledge. Each algorithm balances between complexity, performance, and resource requirements .

CPU scheduling algorithms manage process scheduling in various ways. FCFS (First-Come, First-Served) is simple and easy to implement but can lead to high waiting times due to its non-preemptive nature. SJF (Shortest Job First) optimizes process throughput and minimizes waiting time but requires precise knowledge of process durations, making it less practical. Round Robin (RR) evenly allocates CPU time to processes, improving responsiveness in time-sharing systems, but can result in high context-switching overhead. Each algorithm is suitable for different environments, balancing efficiency, fairness, and resource utilization .

The Unix/Linux operating systems architecture facilitates process management through a hierarchical structure that includes the kernel, shell, and file system. The kernel, at the core, is responsible for managing system resources, including CPU scheduling, memory management, and access to hardware devices. The shell acts as an interface between the user and the kernel, allowing users to execute commands and scripts through a command-line interface. The file system organizes data in a hierarchical directory structure, allowing efficient data management and access control .

Internal commands are built into the shell and execute directly within the shell environment without calling an external program. These are essential for shell functionality, such as 'cd' and 'pwd'. External commands, on the other hand, are separate executable files located in the system's PATH, such as 'ls' and 'grep'. This distinction affects execution as internal commands typically have faster execution because they do not require loading a new program into memory, whereas external commands might involve additional overhead of file location and loading .

You might also like