2. Explain Inode structure and the Superblock of a Unix file system .
How many
superblocks are available in Linux ?
Ans ->
The System V UNIX system runs with 13 entries in the Mode table of contents.
1. The blocks marked "direct" contain the numbers of disk blocks that contain real data.
2. The block marked "single indirect" refers to a block that contains a list of direct block
numbers. To access the data via the indirect block, the kernel must read the indirect
block, find the appropriate direct block entry, and then read the direct block to find
the data.
3. The block marked "double indirect" contains a list of indirect block numbers,
4. The block marked "triple indirect" contains a list of double indirect block numbers.
Superblock
The super block consists of the following fields:
• the size of the file system,
• the number of free blocks in the file system,
• a list of free blocks available on the file system,
• the index of the next free block in the free block list,
• the size of the mode list,
• the number of free inodes in the file system,
• a list of free inodes in the file system,
• the index of the next free Mode in the free mode list,
• lock fields for the free block and free mode lists,
• a flag indicating that the super block has been modified,
The kernel periodically writes the super block to disk if it had been modified so that it is
consistent with the data in the file system.
6.Explain the format of a typical ELF file . What is the difference between a shared
object file and an executable file ? How to create a shared library ? What is the
name of an executable in Android ?
Ans ->
An ELF ( Executable and Linkable Format ) file is binary file format used for executable files ,
object code , shared libraries , and core dumps on Unix and Unix-like operating systems .
Difference between a shared object file and an executable file:
Shared Object file Executable file
1. Contain code and data that can be 1. Contains machine code that can
shared among multiple processes. be executed directly by OS .
2. Loaded into memory by the operating 2. Loaded into memory and
system when needed. executed directly .
3. Used as a library by programs that need 3. Self – contained program with
its functions or variables . all necessary code and data.
4. Smaller in size than executable files . 4. Larger in size than shared object
5. Improves code reusability and reduces files .
memory usage by allowing multiple 5. Cannot be shared among
programs to share the same code and multiple processes.
data.
Name of an executable in Android :
Each Android application is packaged as an APK ( Android Package Kit ) file , which
contains the executable code , resources , and other assets needed to run the
application .
The APK file has a unique package name , which is specified in the
AndroidManifest.xml file in the root of the package .
8. Explain signal mechanism with example. Enlist various signals available in Unix .
Name modern version of signal () system call . How many signals are available in
Linux ?
Ans ->
Signals inform processes of the occurrence of asynchronous events. Processes may send
each other signals with the kill system call, or the kernel may send signals internally.
There are 19 signals in the System V (Release 2) UNIX system :
The treatment of signals has several facets, namely how the kernel sends a signal to a
process, how the process handles a signal, and how a process controls its reaction to signals.
1) To send a signal to a process, the kernel sets a bit in the signal field of the process
table entry, corresponding to the type of signal received. If the process is asleep at an
interruptible priority, the kernel awakens it. The job of the sender (process or kernel)
is complete.
2) A process can remember different types of signals, but it has no memory of how
many signals it receives of a particular type. For example, if a process receives a
hangup signal and a kill signal, it sets the appropriate bits in the process table signal
field, but it cannot tell how many instances of the signals it receives. The kernel
checks for receipt of a signal when a process is about to return from kernel mode to
user mode and when it enters or leaves the sleep state at a suitably low scheduling
priority .
3) The kernel handles signals only when a process returns from kernel mode to user
mode. Thus, a signal does not have an instant effect on a process running in kernel
mode. If a process is running in user mode, and the kernel handles an interrupt that
causes a signal to be sent to the process, the kernel will recognize and handle the
signal when it returns from the interrupt. Thus, a process never executes in user
mode before handling outstanding signals.
4) A process can choose to ignore signals with the signal system call. In the algorithm
issig, the kernel simply turns off the signal indication for signals the process wants to
ignore but notes the existence of signals it does not ignore.
Various signals :
SIGABRT – abort () -> terminate process or program abruptly
SIGALRM – alarm(10) -> after 10 seconds this signal will be generated
SIGBUS – hardware dependent fault
SIGCLD / SIGCHLD – generated when child process stops/terminates
SIGEMT – Emulation trap
SIGFPE – floating point error
SIGIO – I/O event generated
SIGPOLL – Pollable device (polling device - checks whether data has sent or received )
SIGPROF – profile applications ( Gprof )
SIGKILL – killing a process
SIGTERM – terminating a process
SIGPWR
SIGCONT – continue
SIGSTOP – (ctrl z) -> suspend a process
SIGSYS – when machine is executing illegal system call
SIGUSR1/SIGUSR2 – user defined signals ( apache makes use of such signals )
SIGVTALRM – virtual timer
SIGTTOU/SIGT
IN – defines a functionality related to background process
10.Program to show how data can be transferred from client to server using sockets
Ans ->
gfgcode
server.py
# start the ser ver:
$ python server.py
Socket successfully created
socket binded to 12345
socket is listening
Got connection from ('127.0.0.1', 52617)
# start the client:
$ python client.py
Thank you for connecting
1. Explain the working of the bash shell. Draw the necessary diagram. Enlist the
different functionality available in bash shell?
->The shell reads a command line from its standard input and interprets it
according to a fixed set of rules. If the shell recognizes the input string as a
built-in command (for example, commands cd, for, while and others), it
executes the command internally without creating new processes; otherwise, it
assumes the command is the name of an executable file.
The shell forks and creates a child process, which execs the program that the
user specified on the command line. The parent process, the shell that the user
is using, waits until the child process exits from the command and then loops
back to read the next command.
Functionality:
The shell uses standard system calls to provide sophisticated functions. The
shell uses the system calls to provide functions like interpret user commands,
redirecting standard input, standard output and standard error, spawning
processes, setting up pipes between spawned processes, synchronizing
execution with child processes, and recording the exit status of commands. In
addition shell provides the functions- Shell scripting and shell expansion.
2. what is brk() system call? Compare brk() and mmap() syscall. Give an
example where mmap is more useful than malloc?
-> A process may increase or decrease the size of its data region by using the
brk() system call.
The syntax for the brk system call is brk (endds) ;
where endds becomes the value of the highest virtual address of the data
region o the process (called its break value)
b)
brk() and mmap() are both system calls used in Unix-based operating systems
for memory management, but they have some significant differences in their
usage and functionality. Here are some of the key differences:
-brk() is a traditional way of allocating memory in UNIX -- it just expands the
data area by a given amount. mmap() allows you to allocate independent
regions of memory without being restricted to a single contiguous chunk of
virtual address space.
-brk() is used to allocate memory from the heap region of a process's address
space, while mmap() is used to create new memory mappings or map files into
a process's address space.
-brk() is commonly used for small, simple allocations, while mmap() is used for
larger, more complex allocations, such as mapping files into memory or
creating shared memory regions.
-brk() changes the size of the heap segment in a process's address space, while
mmap() creates new mappings at specific addresses in a process's address
space.
C)
malloc() uses the data space for "small" allocations and mmap() for "big" ones,
for a number of reasons, including reducing memory fragmentation.
mmap() is often more useful than malloc() in situations where large amounts
of memory need to be allocated, especially when dealing with files.
3. write and explain file descriptor table, file table, inode table and file system
layout in detail.
The file table is a global kernel structure, but the user file descriptor table is
allocated per process.
The file table keeps track of the byte offset in the file where the user's next
read or write will start, and the access rights allowed to the opening process.
The user file descriptor table identifies all open files for a process.
When executing read and write system calls, the kernel uses the file descriptor
to access the user file descriptor table, follows pointers to the file table and
inode table entries, and, from inode, finds the data in the file.
4. explain ptrace() system call .explain how this syscall used for debugging
applications.
ptrace() is a system call in Unix-based operating systems that allows a process
to trace and control the execution of another process. It is primarily used by
debuggers and other system-level tools for debugging and monitoring
processes.
Syntax of ptrace syscall :
Ptrace(cmd,pid,addr,data);
Where cmd specifies various commands such as reading data, writing
data,resuming execution. Pid is the process id of traced process, addr is the
virtual address to be read or written in child process, and data is an integer
value to written.
how ptrace() might be used in a debugging scenario:
1. The debugger process calls ptrace(PTRACE_ATTACH, pid, 0, 0) to attach
to the target process with process ID pid.
2. Once attached, the debugger can call ptrace() with various options to
control the execution of the target process.
3. This allows the debugger to set breakpoints, step through code, and
inspect the state of the process at various points in its execution.
Ptrace example:
5. What is pregion? Explain the region table. What operations can be done
on Pregion. What additional data structure are required for
implementing pregions?
->> Each process contains a private per process regions table, called a pregion.
The pregion entry contains a pointer to an entry in the region table, and
contains starting virtual address of the region. pregion are stored in process
table, or u-area, or a separately allocated memory space, according to the
implementation.
Region table contains information such as, to determine where it contents are
located in the physical memory. Each process contains a private per process
regions table.
Operations can be done on pregion are allocations, mapping, swapping, paging
, deallocation.
Additional data structures- page table, page directory, page frame, protection
bits, free list, swap file.
6.. draw the state transition diagram of unix process. What is zombie state?
What syscall used for termination of process?
When process executes the exit () system call it goes in zombie state. It is the
final state of the process.
System call used for the termination of process is exit(), abort().
Q.)Write simple flask based sever in python. What is decorator? What is
WSGI?
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
If you want to develop on your local computer, you can do so easily. Save this
program as server.py and run it with python server.py.
$ python server.py
* Serving Flask app "hello"
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
a decorator is a design pattern that allows you to modify the functionality of a
function by wrapping it in another function.
WSGI is the Web Server Gateway Interface. It is a specification that describes
how a web server communicates with web applications, and how web
applications can be chained together to process one request.