Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Operating System

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Operating System (22CS005)

Practical File
Of
Operating System
(22CS005)
Submitted

in partial fulfillment for the award of the degree of

BACHELOR OF ENGINEERING
in

COMPUTER SCIENCE & ENGINEERING

CHITKARA UNIVERSITY

CHANDIGARH-PATIALA NATIONAL HIGHWAY


RAJPURA (PATIALA) PUNJAB-140401 (INDIA)

JUNE 2024

Submitted To: Submitted By:


Faculty name: Dr. Meenakshi Malhotra Name: Kartikeya Jain
Designation: Assistant Professor Roll No: 2310991865
Operating System (22CS005)

List of Practical (Operating System 22CS005)

S. No Practical Remarks
1.  Installation and configuration of Linux
Operating system.
 To illustrate basic of GCC compiler i.e.,
compilation and execution of a program
 Time stamping in linux
 Automating the execution using make file
2. Implement the basic and user status commands like:
su, sudo, man, help, history, who, who am i, id,
uname, uptime, free, tty, cal, date, hostname, reboot,
clear
3. Implement the commands that is used for Creating
and Manipulating files: cat, cp, mv, rm, ls and its
options, touch and their options, which is, where is,
what is
4. Implement Directory oriented commands: cd, pwd,
mkdir, rmdir, Comparing Files using diff, cmp,
commands
5. Write a program and execute the same to
demonstrate how to use terminal commands in C
program (using system() function)
6. Write a program to implement process concepts
using C language by printing process Id.
7. Write a program to create and execute process using
fork() and exec() system calls.
8. Implement FCFS , SIF , priority scheduling and
round robin scheduling in C Language.
9. Implement DeadLock In C-Language.

10. File system: Introduction of File system, File system


architecture and file types.
Operating System (22CS005)

Experiment – 1

Aim:-
Installation and configuration of Linux Operating system.

Theory:-
Linux is an open source , Unix-like operating system kernel .It is like
the heart of a computer, managing everything that goes on inside. It's
free to use and built by a community of developers worldwide. With
Linux, we can customize our computer just the way we like it, from
how it looks to what it does. It's super reliable, meaning it doesn't crash
often, and it's great for running all kinds of programs, from browsing the
internet to creating documents and even powering big servers for
websites. . Popular Linux distributions include Ubuntu, Fedora, CentOS
, Debian, and Arch Linux, each with its own characteristics and package
management systems.
Operating System (22CS005)

System Requirement:- Before installation, ensure that your hardware


meets the minimum requirements specified by the chosen Linux
distribution. Consider factors such as CPU architecture, RAM, storage
space, and graphics capabilities.

Linux Distributions:-
Linux distributions, or "distros," are customized versions of the Linux
operating system. They vary in pre-installed software, desktop
environments, and intended use. Popular distros include Ubuntu for
user-friendliness, Debian for stability, Fedora for cutting-edge features,
CentOS for servers, and Arch Linux for minimalism. Each distro offers
unique features and community support.

1. Ubuntu:
 Description: Ubuntu is User-friendly Linux distro based on Debian,
offering stability with up-to-date features. Supports various desktop
environments, widely used for desktops, servers, and cloud
deployments.
 Package Management: APT (Advanced Package Tool)
 Desktop Environment: Ubuntu offers desktop environments like
GNOME (default), KDE Plasma, Xfce, LXQt, and MATE for users to
customize their experience.
Operating System (22CS005)
2. Fedora:
 Description: Sponsored by Red Hat, Fedora is a cutting-edge
distribution that emphasizes the use of the latest software and
technologies.
 Package Management: DNF (Dandified YUM)
 Desktop Environment: Default is GNOME, but it supports various
desktop environments.

3. Debian:
 Description: Debian is known for its stability and commitment to
free and open-source software principles. It serves as the foundation
for several other distributions.
 Package Management: APT (Advanced Package Tool)
 Desktop Environment: Varies, can be customized during
installation.

4. CentOS:
 Description: Derived from the sources of Red Hat Enterprise Linux
(RHEL), CentOS is a free, community-supported distribution known
for its stability and reliability.
 Package Management: YUM (Yellowdog Updater, Modified)
 Desktop Environment: Primarily used for servers; desktop
environments can be added as needed.

5. Arch Linux:
 Description: Arch Linux is a rolling release distribution known for its
simplicity and customization. It follows a "do-it-yourself" philosophy.
 Package Management: Pacman
 Desktop Environment: None by default; users can choose and install
their preferred desktop environment.

6. openSUSE:
Operating System (22CS005)
 Description: openSUSE is a distribution sponsored by SUSE Linux
GmbH and is known for its robustness and user-friendly
administration tools.
 Package Management: Zypper
 Desktop Environment: Default is KDE Plasma, but it supports various
desktop environments.

7. Mint:
 Description: Linux Mint is based on Ubuntu and Debian and is
designed to be user-friendly, with a focus on providing a familiar
desktop experience for users switching from other operating systems.
 Package Management: APT (Advanced Package Tool)
 Desktop Environment: Cinnamon (default), MATE, Xfce.

Procedure:- If we want to experiment with Linux without affecting our


main operating system, we can use a virtual machine (VM). We can run
Linux directly on our primary OS, whether it’s Mac OS or Windows
without affecting our main OS System. In this, we will specifically talk
about installing a Linux distribution called “Ubuntu” inside our virtual
machine software. However, the instructions are bit similar for running
other Linux distributions. We will go through installing virtual box,
creating a virtual machine within it and installing the latest Ubuntu
distribution to the virtual machine.

About Virtual-Box:- Virtual-Box is an open-source hypervisor that is


developed by Oracle. It is similar to an emulator that creates and runs
virtual machines where we can install different Operating Systems
without having to tinker with our disc partition or worrying about
impacting our primary operating system. Instead, we run a different OS,
like Ubuntu, as if it were another program running on our computer.
Operating System (22CS005)

Virtual-Box,, search Oracle Virtual


Installing Virtual-Box:- To install Virtual Virtual-
Box on search engine. Open the website, Select and downl download the
correct package for our primary operating system. (The host operating
system in virtualization terminology).
Operating System (22CS005)
On selecting windows host, it will automatically select the variant that
our device supports and download an exe file for it on our system.

Open the package, install VirtualBox as you would typically install a


program. Feel free to use the default installation options.

Create a VM Provisioning a machine: Once virtual box is installed on


out machine, start the program and we should see the Virtual-Box
manager windows open.

To download ubuntu :-
Prepare Disk Space: Make sure we have enough free space on your
laptop's hard drive to install Ubuntu. we may need to resize our existing
partitions to create space for Ubuntu.
Operating System (22CS005)
Download Ubuntu:- After downloading the Virtual-Box , download an
Ubuntu software file in the device by following simple steps

 Search for ubuntu on search engine and selct get ubuntu.


 Select download ubuntu desktop button.
 Download the latest version of it by simply clicking on it.
Operating System (22CS005)
Operating System (22CS005)

Setting up:- Follow the given steps:

1. Mount the ISO File: Once the ISO file is downloaded, we can
mount it by simply double clicking on it in our file manager.

2. Start the Installation: Within the mounted ISO file, we will find
the installer program. Run the installer program to start the Ubuntu
installation process.

3. Follow the Installation Wizard: The installer will guide us


through the installation process. Choose own language, keyboard
layout, and other settings. When prompted, select the option to
install Ubuntu alongside the existing operating system or replace it
with Ubuntu.

4. Configure Ubuntu: Create a user account, set your time zone, and
choose your preferences for updates and additional software during
the installation process.

5. Wait for Installation to Complete: The installation process may


take some time. Once it's finished, we will be prompted to restart
your laptop.
Operating System (22CS005)
Operating System (22CS005)

GCC COMPILER

INTRODUCTION:- GCC (GNU Compiler Collection) is a suite of


versatile compilers supporting languages like C, C++, Objective-C. It
offers optimization, supports various architectures, integrates with
development environments, and is open-source.
BASICS:- It translates source code into machine code for various
architectures and offers optimization options for performance
enhancement.

COMPILATION:- To compile a program with GCC:


 Write code.
 Open terminal.
 Navigate to code directory.
 Compile using "gcc filename.c -o output_filename".
 Execute with "./output_filename".

EXECUTION:- To execute a compiled program:


 Open Terminal or Command Prompt.
 Navigate to the directory containing the executable.
 Run the program using "./executable_name".
Operating System (22CS005)

TIME STAMPING IN LINUX

In Linux, we can generate a timestamp using the date command. Here's


how you can do it:
 Current Timestamp: To get the current timestamp, simply type
date in the terminal and press Enter.
 Specific Format: You can specify the format of the timestamp
using formatting options with the date command. For example:

 Timestamp from File: To get the timestamp of a file, you can use
the stat command followed by the file name.
 Modification Time: If you're interested in the last modification
time of a file, you can use the -c %y option with the ls command.
Operating System (22CS005)

Automation the execution using the makefile

What's a Makefile: It's like a set of instructions for our computer. we


write it to tell our computer what to do, like compiling code or cleaning
up files.
Targets are Goals: In a Makefile, we set targets, which are like goals.
Each target represents something we want to achieve, such as compiling
your code or deleting unnecessary files.
Dependencies are Needs: Targets often depend on other things, like
files or other targets. These are called dependencies. For example, to
compile our code, we might need the source files.
Commands are Actions: Under each target, we write commands.
These are the actions our computer should take to achieve the target.
For compiling code, the command might be to use a specific compiler.
Using Make: When we run the make command in your terminal, it
reads our Makefile and figures out what needs to be done to reach the
targets we specify.
Why Use Makefiles?: They make repetitive tasks easier by automating
them. It's like giving our computer a recipe to follow so we don't have to
do everything manually.
Makefiles Everywhere: Makefiles work on different operating
systems, not just Unix-like ones, so you can use them regardless of what
kind of computer we have.
Operating System (22CS005)

EXPERIMENT-2
Implement the basic and user status commands
 Sudo :- It allows authorized users to perform administrative tasks
that require elevated permissions, such as installing or removing
software, modifying system configurations, or managing system
services.
 Man :- man stands for "manual" it includes commands like system
calls, library functions, configuration files, and more.
 Uname:- it used to display the name of the person using it.
 Help:- help is a built-in command that provides information and
usage instructions for built-in shell commands.
 Who:- it displays information about users currently logged in,
including usernames and login times.
 Whoami :- it displays the username associated with the currently
active user session.
 Cal:- it displays a calendar for a specified month or the current
month by default.
 History:- it gives all the commands which we can use.
 Date:- it displays the current date and time information according
to the system's settings.
 Clear:-this command is used to clear the terminal.
 Hostname:- it gives the name of the software we were using
In this case (ubuntu) is our hostname
Operating System (22CS005)
Operating System (22CS005)
Operating System (22CS005)
Operating System (22CS005)

EXPERIMENT – 3
COMMANDS FOR CREATING AND MANIPULATING FILES:-
 Cat:- cat command displays the content of one or more files in the
terminal.
 Cp:-cp command is used to copy the content of any file to another
new one.
 Mv:- The mv command is used to move or rename files and
directories within the file system.
 Rm:- The rm command is used to remove or delete files and
directories from the file system.
 Ls:- ls command is used to list all the files present in the directory.
 Touch:- The touch command is used to create an empty file or
update the access and modification timestamps of an existing file.
Operating System (22CS005)
Operating System (22CS005)

EXPERIMENT -4
IMPLEMENT DIRECTORY ORIENTED COMMANDS:-

 Cd:- The “Change Directory” command is used to change the


current working directory in the command line interface.
 Pwd:- The “print working directory” command is used to print the
current working directory in the command line interface.
 Mkdir:- "make directory" command in an OS creates a new
directory with the specified name within the current working
directory.
 Rmdir:-“remove directory” command In an OS is used to delete
the directory with a specified name within the current working
directory.
Operating System (22CS005)
Operating System (22CS005)

EXPERIMENT - 5
Write a program and execute the same to demonstrate how to use
terminal commands in C Program(using system( ) function ):

THEORY:-
Using the system() function in C allows you to execute terminal
commands directly from within a C program. This can be useful for
automating tasks or interacting with the operating system.

This is how we can run terminal commands using C program.


Operating System (22CS005)

EXPERIMENT - 6
Write a program to implement process concepts using C language
by printing process Id.
Process Id :-
A process ID (PID) is a unique identifier assigned to each running
process in an operating system. It is used to identify and manage
processes in a system .
Operating System (22CS005)

EXPERIMENT -7
What is fork? :- It's like making a copy of your program while it's
running.We create a new process that's a copy of the current one.
Why we use it :-We might use it when you want to do two things at
once in your program, like running a server while also handling user
requests.

Write a program to create and execute the process using fork( ) system
call.
Q1}
Operating System (22CS005)

Q2}

20 times “1”
Operating System (22CS005)

Q3}

-SINCE I HAVE USED ONLINE COMPILER, THEREFORE I HAVE GET


DIFFERENT OUTPUTS IN DIFFERENT RUN OF THE CODE.
-THIS
THIS IS BECAUSE IT DEPENDS ON THE WAY OUR COMPILER READS
THE CODE.
Operating System (22CS005)

EXPERIMENT :- 8
AIM: Implement FCFS , SIF , priority scheduling and round robin scheduling in
C Language.

THEORY:
First Come, First Served (FCFS) also known as First In, First Out (FIFO) is the
CPLI scheduling algorithm in which the CPU is allocated to the processes in the
order they are queued in the ready queue FCFS follows non preemptive
scheduling which mean once the CPU is allocated to a process it does not leave
the CPU until the process will not get terminated or may get halted due to some
1/0 interrupt
Shortest Job First (SJF) is an algorithm in which the process having the
smallest execution time is chosen for the next execution. This scheduling method
can be preemptive or non-preemptive. It significantly reduces the average
waiting time for other processes awaiting execution. The fall form of SIF is
Shortest Job First
Priority Scheduling is a method of scheduling processes that is based on
priority. Lt this algorithms, the scheduler selects the tasks to work as per the
priority. The processes with higher priority should be carried out first, whereas
jobs with equal priorities are carried out or a round-robin or ICFS basis. Priority
depends upon memory requirements, time requirements, etc.
Round Robin Scheduling comes from the round-robin principle, where each
person gets an equal share of something in turns. It is the oldest, simplest
scheduling algorithm, which is mostly used for multitasking In Round-robin
scheduling, each ready task runs turn by turn only in a cyclic queue for a limited
time slice. This algorithm also offers starvation free execution of processes
Operating System (22CS005)

PROCEDURES:
(A). FCFS: (First Come First Serve)
Operating System (22CS005)

(B). SJF: (Shortest Job First)


Operating System (22CS005)

(c) PRIORITY SCHEDULING:-


Operating System (22CS005)

(D) ROUND ROBIN SCHEDULING :-


Operating System (22CS005)

EXPERIMENT :- 9
AIM:- Implement DeadLock In C-Language.
THEORY:-
Deadlock in C occurs when multiple processes compete for resources
and get stuck waiting for each other to release resources they need. It
happens when each process holds a resource and waits for another
resource held by another process. In C, this can result from improper
synchronization mechanisms like semaphores. Deadlock prevention
strategies include resource ordering, timeout mechanisms, and avoiding
circular wait conditions. Proper resource management and
synchronization techniques are crucial to prevent deadlock situations in
C programs.
Operating System (22CS005)

PROCEDURES:-

Resource Allocation: Multiple processes or threads attempt to acquire


exclusive access to resources within the system.
Resource Hold and Wait: Each process holds onto at least one
resource while waiting to acquire additional resources that are currently
held by other processes.
Circular Wait: A circular dependency forms among the processes,
where each is waiting for a resource held by another process in the
cycle.
Deadlock Formation: As a result of the circular wait, none of the
processes can proceed, leading to a deadlock situation where they're
indefinitely blocked.
System Stagnation: The deadlock state persists, causing the system to
stagnate, unable to make progress with the available resources.
Operating System (22CS005)

Experiment: 10
File system: Introduction of File system, File system architecture and
file types.
A file system is a method an operating system uses to store, organize,
and manage files and directories on a storage device. Some common
types of file systems include:
1. FAT (File Allocation Table): An older file system used by older versions
of Windows and other operating systems.
2. NTFS (New Technology File System): A modern file system used by
Windows. It supports features such as file and folder permissions, compression,
and encryption.
3. ext (Extended File System): A file system commonly used on Linux and
Unix-based operating systems.
4. HFS (Hierarchical File System): A file system used by macOS.
5. APFS (Apple File System): A new file system introduced by Apple for
their Macs and iOS devices.

How file systems work


A file system stores and organizes data. It can be thought of as a type of index for
all the data contained in a storage device. In addition to SSDs and HDDs, file
systems are used for optical disks, flash drives and magnetic tape.
File systems specify conventions for naming files, including the maximum
number of characters in a name, which characters can be used and how long the
file name extension can be. In many file systems, file names are not case
sensitive.
Operating System (22CS005)

Along with a file's content data, a file system maintains metadata about the files
along with other information. The metadata might include details such as the file
size, creation date or location in the directory.
Most file systems organize files in a directory hierarchy, with a file's location
described by its path within the directory structure. The directories are organized
into an inverted hierarchical tree structure, with the root directory at the top. Each
file is placed in a directory or subdirectory at the desired location within the tree
structure.

File system architecture


File systems handle both the physical and logical operations associated
with managing files. Although they take different approaches to storing
file data, they commonly separate metadata from the file's content data.
They also store a small amount of other data types, which are used for
maintaining the file system and facilitating file access.
Operating System (22CS005)

A file system divides a partition into blocks, and their size depends on
the file system. Most of the blocks are used for the files' content data.
The remaining blocks are divided between the files' metadata and the
file system's management data. Figure 2 provides a conceptual overview
how a file system in a Unix-like environment might organize the data
across the individual blocks. In this case, the metadata is stored in index
nodes (inodes). An inode is an indexable data structure that maintains
details about a file or directory.

File systems architecture in a Unix-like environment.

The management data occupies the first few blocks, followed by the
inode metadata and then the content data blocks, which consume most
of the storage. Here's a breakdown of the different block types:
• Super block. The block contains information about the file system
itself, acting as its own metadata repository. For example, the super
block might include details about the file system type, total number of
blocks, number of inodes or other components.
• Data block bitmap. The block contains a simple bitmap that
indicates which data blocks are used or unused. A value of 1 indicates
the block is used, and a value of 0 indicates it is unused.
Operating System (22CS005)

• Inode bitmap. The block contains a simple bitmap that indicates


which inodes are used or unused. A value of 1 indicates the inode is
used, and a value of 0 indicates it is unused.
• Inodes. The file system maintains an inode for each file and
directory. The inode is identified by a unique number and includes the
metadata for the associated file or directory. It also includes the address
of the data blocks that contain the file's content. In this way, the inode
can be used to quickly locate the file.
• Content data blocks. All file content is stored in the data blocks.
These blocks represent most of the occupied blocks of the file. The
figure shows only a portion of the content data blocks.

You might also like