Assignment – 5
Operating System And Unix Shell
Programing Lab
BCO290
B.Sc. Information Technology
Submitted By : Submitted To :
Vinay Yadav Ms. Barkha Nandwana
2023350666
Q1. What do you understand by Unix Operating
System and explain it’s features?
Unix is a powerful and versatile operating system that originated in
the 1970s at Bell Labs. It has since evolved into various flavors,
including Linux and macOS. Unix is known for its stability, security,
and flexibility, making it a popular choice for servers, workstations,
and embedded systems.
Here are some key features of Unix:
1. Multi-user and Multi-tasking: Unix allows multiple users to
interact with the system simultaneously, each running multiple
processes concurrently. This capability enables efficient
resource utilization.
2. Hierarchical File System: Unix organizes files and directories
in a hierarchical structure, with the root directory ("/") at the top.
This hierarchical file system facilitates organization, navigation,
and management of data.
3. Shell: Unix provides a command-line interface known as the
shell, which allows users to interact with the system by typing
commands. The shell interprets these commands and executes
them, facilitating automation and scripting.
4. Portability: Unix was designed to be portable across different
hardware architectures. This portability enables Unix-based
operating systems to run on a wide range of devices, from
mainframes to smartphones.
5. Networking: Unix has robust networking capabilities built into
its core, making it well-suited for networked environments. It
includes utilities for communication, file sharing, remote access,
and network administration.
6. Security: Unix incorporates robust security features, including
file permissions, user authentication, and encryption
mechanisms. These features help protect system resources and
data from unauthorized access and malicious activities.
7. Modularity: Unix follows a modular design philosophy, with
distinct components performing specific functions. This modular
architecture facilitates system customization, maintenance, and
scalability.
8. Open Standards and Interoperability: Unix adheres to open
standards and protocols, enabling seamless interoperability with
other systems and applications. This interoperability fosters
compatibility and integration in heterogeneous computing
environments.
9. Extensibility: Unix supports extensibility through various
programming interfaces and development tools. Users can create
custom applications, utilities, and system enhancements to meet
specific requirements.
10. Community and Documentation: Unix benefits from a
vibrant community of users, developers, and contributors who
actively collaborate, share knowledge, and provide support.
Extensive documentation and resources are available to help
users learn and troubleshoot Unix systems effectively.
Q2. Explain kernel architecture in Unix.
The kernel is the core component of the Unix operating system,
responsible for managing system resources, providing essential
services, and facilitating communication between hardware and
software components. The kernel architecture in Unix is designed to
be modular, efficient, and flexible, allowing it to adapt to different
hardware configurations and computing environments.
Here are the key components and layers of the kernel architecture in
Unix:
1. Process Management:
The process management subsystem is responsible for
creating, scheduling, and terminating processes.
It maintains process control blocks (PCBs) for each
process, containing information such as process ID, state,
and priority.
The scheduler determines which processes are allowed to
run and in what order, optimizing system resource
utilization.
2. Memory Management:
Memory management handles the allocation, deallocation,
and protection of memory resources.
It manages physical and virtual memory, including the
translation of virtual addresses to physical addresses
through techniques like paging and segmentation.
Memory protection mechanisms prevent unauthorized
access to memory regions, ensuring system stability and
security.
3. File System:
The file system manages the storage and organization of
files and directories on disk.
It provides an interface for creating, reading, writing, and
deleting files, as well as for navigating directory
structures.
File system drivers interface with storage devices and
handle low-level operations such as disk I/O.
4. Device Drivers:
Device drivers control and communicate with hardware
devices such as disks, network interfaces, and input/output
devices.
Each device driver implements the necessary interfaces
and protocols to interact with its corresponding hardware
component.
Device drivers abstract hardware details and provide a
standardized interface for higher-level software to access
hardware resources.
5. System Calls:
System calls provide a mechanism for user-space
processes to request services from the kernel.
They allow processes to perform privileged operations
such as I/O, process management, and memory
management.
System calls are the interface between user-space
applications and the kernel, facilitating interaction with
underlying hardware and system resources.
6. Interprocess Communication (IPC):
IPC mechanisms allow processes to communicate and
synchronize with each other.
Examples of IPC mechanisms in Unix include pipes,
sockets, shared memory, and signals.
These mechanisms enable collaboration and coordination
between processes, facilitating the development of
complex, multi-process applications.
7. Network Stack:
The network stack implements networking protocols and
services, enabling communication over networks.
It handles tasks such as packet routing, transmission,
reception, and protocol encapsulation.
The network stack supports various networking
technologies and protocols, including TCP/IP, UDP, and
Ethernet.
Q3. Write any five internal commands in Unix.
1. cd: The cd command is used to change the current working
directory.
For example: cd /path/to/directory
2. pwd: The pwd command stands for "print working directory"
and is used to display the current directory's full path.
For example: pwd
3. echo: The echo command is used to print text to the terminal. It
is commonly used for displaying messages and for shell
scripting. For example: echo "Hello, World!"
4. alias: The alias command is used to create shortcuts or aliases
for other commands. It is helpful for creating custom command
shortcuts or for overriding default behavior.
For example: alias ll='ls -alF'
5. history: The history command is used to display a list of
previously executed commands. It can be helpful for reviewing
command history and repeating or modifying past commands.
For example:history
Q4. Write any five External commands in Unix.
1. ls: The ls command is used to list directory contents. It displays
information about files and directories in the specified directory.
For example: ls -l
2. grep: The grep command is used for searching text patterns
within files. It searches for patterns in text files and prints lines
that match the specified pattern.
For example: grep "pattern" file.txt
3. cat: The cat command is used to concatenate and display the
contents of files. It can also be used to create new files and
concatenate files.
For example: cat file1.txt file2.txt
4. chmod: The chmod command is used to change the permissions
of files and directories. It can modify permissions for the owner,
group, and others.
For example: chmod u+x file.sh
5. cp: The cp command is used to copy files and directories from
one location to another. It can copy single files, multiple files, or
entire directories.
For example:cp file1.txt file2.txt
Q5. Explain System call and types of System Calls.
A system call is a mechanism provided by the operating system that
enables user-level processes to request services from the kernel,
which is the core component of the operating system. System calls
provide an interface for applications to interact with the underlying
hardware and operating system resources in a controlled and secure
manner. When a user-level process needs to perform privileged
operations or access resources managed by the kernel, it invokes the
appropriate system call, which transfers control to the kernel. The
kernel then executes the requested operation on behalf of the process
and returns the result back to the calling process.
Here are some common types of system calls:
1. Process Control:
These system calls are used for managing processes, such
as creating, terminating, and manipulating processes.
Examples: fork(), exec(), exit(), wait().
2. File Management:
These system calls are used for performing operations on
files and directories, such as opening, closing, reading,
writing, and manipulating file attributes.
Examples: open(), read(), write(), close(), mkdir(),
unlink().
3. Device Management:
These system calls are used for managing devices,
including input/output operations, device control, and
device status inquiries.
Examples: read(), write() (for devices), ioctl(), fcntl().
4. Information Maintenance:
These system calls are used for retrieving information
about system resources, such as processes, users, and
system configuration.
Examples: getpid(), getuid(), gettimeofday().
5. Communication:
These system calls are used for inter-process
communication (IPC) and network communication.
Examples: pipe(), socket(), send(), recv(), connect().
6. Memory Management:
These system calls are used for allocating and managing
memory resources, including allocating and freeing
memory, mapping files into memory, and changing
memory protection attributes.
Examples: brk(), mmap(), munmap(), sbrk().
7. Synchronization:
These system calls are used for synchronization and
coordination between processes or threads.
Examples: semaphore, mutex, condition variable.
Q.6 Explain Fork System call with creation of child-
parent process.
The fork() system call is one of the fundamental process
control system calls in Unix-like operating systems, including Linux.
It is used to create a new process, known as the child process, which
is a copy of the calling process, known as the parent process. The
child process runs concurrently with the parent process and typically
executes a different code path or performs a different task.
Here's an overview of how the fork() system call works and how it
creates a child-parent process:
1. Invoking fork():
When a program executes the fork() system call, the
operating system creates a new process, which is an exact
copy of the calling process. This new process is referred to
as the child process.
2. Copy-on-Write Mechanism:
To optimize performance and memory usage, most modern
Unix-like operating systems implement a copy-on-write
mechanism for fork(). This means that initially, the child
process shares the same memory space as the parent
process. The physical memory is not copied immediately
but is shared between the parent and child processes.
Copy-on-write ensures that memory pages are copied only
when they are modified by either the parent or the child
process.
3. Return Values:
After fork() is called, both the parent and child processes
continue executing from the point of the fork() call.
In the parent process, the return value of fork() is the
process ID (PID) of the newly created child process.
In the child process, the return value of fork() is 0,
indicating that it is the child process.
If fork() fails to create a child process, it returns -1,
indicating an error.