16-17 Final Question Solve
16-17 Final Question Solve
Operating System: The operating system itself is not a system program. Instead, it is the
core software that manages computer hardware and provides services for computer
programs. System programs interact with the operating system to perform tasks and
manage resources.
System Level Service: System level services refer to the various functionalities provided
by the operating system to facilitate the execution and management of applications.
These services may include process management, memory management, file system
access, and device management, among others.
Functionality of the Operating System: This refers to the capabilities and services
offered by the operating system as a whole. These functionalities enable applications to
run efficiently and provide an interface for users to interact with the computer system.
b) Suppose the values 2 and 3 are store in memory locations 940 and 941 respectively.
Now, explain the program execution with figures to store the sum of the two values in
the memory location 941.
AVAILABLE AT:
It is important for a programmer to know which library procedures result in system calls
under certain circumstances and for specific reasons:
System calls are typically more time-consuming than regular library function calls
because they involve a transition from user mode to kernel mode. Therefore,
understanding which library procedures result in system calls allows a programmer to
optimize their code and minimize the number of system calls made, leading to improved
performance.
Knowing which library procedures involve system calls also helps the programmer
understand the potential security implications. System calls can have significant
privileges in the operating system, and if a library procedure results in a system call, it
AVAILABLE AT:
Overall, understanding which library procedures result in system calls allows the
programmer to write more efficient, secure, and reliable code while making the best
use of the underlying operating system services.
2.a) Analyze the following commands and describe which shell feature(s) these are
used:
i) ls mydir > outfilel &
ii) vi *
iii)ls mydir > outfilel & date > outfile2 &
ii) vi *
Shell feature(s) used: Wildcards (globbing)
Explanation: This command opens the "vi" editor and attempts to open all files in the
current directory (matching any file names) for editing. The "*" symbol is a wildcard that
matches any character or set of characters in the shell, which is useful for performing
operations on multiple files at once.
AVAILABLE AT:
lseek(fd, 3, SEEK_SET);: This system call sets the file offset to byte 3 from the beginning
of the file (SEEK_SET). So, the file pointer is moved to byte 3, which is the number 1 in
the sequence.
read(fd, &buffer, 4);: This system call reads 4 bytes from the current file offset (byte 3)
and stores them in the buffer. The buffer will contain the bytes starting from the current
offset: 1, 5, 9, 2.
So, after the read has completed, the buffer will contain the sequence of bytes: 1, 5, 9, 2.
A shell script is a text file that contains a sequence of commands for a UNIX-based
operating system. It is called a shell script because it combines a sequence of
commands, that would otherwise have to be typed into the keyboard one at a time, into
a single script.
Shell scripts contain ASCII text and are written using a text editor, word processor or
graphical user interface (GUI). The content of the script is a series of commands in a
language that can be interpreted by the shell. Functions that shell scripts support
include loops, variables, if/then/else statements, arrays and shortcuts. Once complete,
the file is saved typically with a .txt or .sh extension and in a location that the shell can
access.
AVAILABLE AT:
#!/bin/bash
gzip myfile.txt
3. a) In a multi-user operating system, the operating system must protect users from
Reach other and protect itself from users. However, while providing an operating
environment for all users, the operating system creates this illusion (permission for
read, write, execution, etc.) by creating data paths between user processes and
devices and files. How does UNIX create this illusion?
UNIX creates the illusion of permissions for users by implementing a robust file
permission system based on three types of permissions: read (r), write (w), and execute
(x). These permissions are assigned to three classes of users: owner, group, and others.
When a user interacts with files or directories, the operating system checks their
permissions against the requested operation to determine whether it is allowed or not.
User Identification: Each process running in UNIX is associated with a specific user,
known as the "effective user ID" or "EUID." The EUID determines the permissions
available to the process for accessing files and resources.
File Ownership: Every file and directory in UNIX is associated with an owner and a
group. The owner is the user who created the file, and the group is a collection of users
who share common access rights to the file.
AVAILABLE AT:
Access Control Lists (ACLs): In addition to the standard permissions, some UNIX
systems support ACLs, which provide more fine-grained control over file access by
allowing specific permissions for individual users and groups.
With these mechanisms in place, UNIX can ensure that users can only access files and
resources they have the proper permissions for, protecting users from each other and
the system from unauthorized access.
b) Unix files have a full set of permission bits, including a set-user-ID bit and a
set-group-ID bit. If you turn on the set-group-ID bit for a directory, does it have any
effect? If so, what and why? If not, could you think of some use for this bit?
When the set-group-ID bit (SGID) is turned on for a directory in UNIX, it has an effect on
the files and subdirectories created within that directory. If a new file or directory is
created within a directory with the SGID bit set, the new file or directory inherits the
group ownership of the parent directory, rather than the group ownership of the user
creating the file or directory.
The reason behind this behavior is to ensure that files created within a shared directory
maintain the same group ownership as the parent directory, facilitating group
collaboration and consistent access control.
c) Each user has a username and a number, the UID, why? Wouldn't it be simpler to
record the username of the user as the owner of a file? Why not have a single identifier
for each user?
Having both a username and a UID (user identifier) serves important purposes in
multi-user operating systems like UNIX:
User Convenience: Assigning usernames allows users to easily identify and remember
each other and themselves on the system. It provides a more human-readable
representation of users.
AVAILABLE AT:
Flexibility and Security: Usernames can be changed without affecting the system's
internal processes since UIDs remain constant. This flexibility allows users to update
their display names without affecting their permissions and access rights.
In summary, having both usernames and UIDs provides a balanced approach between
user convenience, system security, and ease of administration in multi-user operating
systems like UNIX.
4.a) The kernel had to locate a free inode and free disk blocks when it created a new
file. How does the kernel know which blocks are free? How does the kernel know
which inodes are free? What method does the file system on your machine use to keep
track of unused blocks and inodes?
When the kernel needs to create a new file, it must find free disk blocks and a free inode
to allocate for the new file. The kernel relies on the file system to keep track of which
blocks and inodes are free and available for allocation.
Free Blocks: The file system maintains a data structure, often called the "free block
bitmap" or "free block list," to track which disk blocks are available for use. This bitmap
is a binary representation, where each bit corresponds to a block on the disk. A "0" bit
indicates that the block is free, and a "1" bit indicates that the block is already allocated
and in use. The kernel can quickly scan this bitmap to find available free blocks.
Free Inodes: Similarly, the file system uses a "free inode bitmap" or "free inode list" to
track which inodes are free for allocation. Each inode represents a file or directory on
the file system. Like the free block bitmap, the free inode bitmap uses bits to represent
the availability of inodes. A "0" bit means the inode is free, and a "1" bit means it is in
use.
AVAILABLE AT:
b) A directory is just a node in a set of linked nodes. Using the pwd command you can
simply know the current directory. Based on the functionalities of pwd answer the
following:
i) What repetitive steps are performed to compute its current directory?
ii) How do we know when we read the top of the tree?
iii) How do we print the directory names in the correct order?
The pwd (print working directory) command displays the current working directory of
the user in the shell.
/
└── home
└── user
└── documents
└── projects
└── current
The pwd command will display the complete path:
/home/user/documents/projects/current.
AVAILABLE AT:
On a terminal special file (e.g., /dev/tty), the read permission controls the ability to read
input from the terminal, and the write permission controls the ability to send output to
the terminal. These permissions determine whether a user or a process can interact
with the terminal device.
The numeric value 000 represents no permissions for the owner, group, and others,
respectively. When you run chmod 000 /dev/yourtty, you are removing all permissions
from the terminal special file.
If you use tty to determine the name of your terminal and then use chmod 000
/dev/yourtty to make your terminal unreadable even to yourself, the result will be that
you lose the ability to read and write from/to the terminal. This means you won't be able
to input commands or see any output on that terminal. You essentially lock yourself out
from interacting with that terminal.
AVAILABLE AT:
When you use cd to change to a directory named dir, you are not physically moving into
that directory. Instead, the shell updates its internal record of the current working
directory to the specified directory. The shell then uses this updated information to
resolve relative pathnames. Relative pathnames are pathnames that do not start with
the root directory ("/") but instead are based on the current working directory.
c) The return value form fork allows a process to determine if it is the parent or child
process. What other technique can a process use?
d) Standard Unix shells do not die when the user sends the interrupt or quit signal
when the child is running. How does a standard Unix shell respond to these signals
when regarding a command line?
d) How a standard Unix shell responds to interrupt or quit signals when regarding a
command line:
When a standard Unix shell is running a command line and receives an interrupt signal
(SIGINT, usually triggered by pressing Ctrl+C) or a quit signal (SIGQUIT, usually triggered
by pressing Ctrl+), it typically responds as follows:
AVAILABLE AT:
In summary, the standard Unix shell reacts to these signals by interrupting or quitting
the current foreground process and returning control to the shell. It allows the user to
stop a running command or produce debugging information when needed.
6.a) What do you know about thread of execution? Explain multiple threads of
execution with proper examples.
Let's consider a simple example of a web server. The web server process receives
incoming client requests and processes them to serve web pages. Instead of handling
each request sequentially, the server can use multiple threads to handle multiple
requests concurrently. Each thread will be responsible for processing one client request
independently. This way, the web server can efficiently serve multiple clients
simultaneously, making better use of the available resources.
AVAILABLE AT:
Signal Handling:
signal: Sets up signal handlers for specific signals.
kill: Sends a signal to a specified process or process group.
The syntax of the unconditional statement in UNIX is the if statement without any
condition, followed by the then keyword.
#!/bin/bash
if true; then
echo "This will always be executed."
fi
AVAILABLE AT: