0% found this document useful (0 votes)
13 views12 pages

Ao Answer

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views12 pages

Ao Answer

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

True or False Justify: “The kernel is a separate set of process that run in

parallel to user processes

= False.

The kernel is not a separate set of processes that run in parallel to user processes; rather, it is the
core component of an operating system that manages system resources and facilitates
communication between hardware and software.

b ) What are the 4 different conditions for the pid argument of kill system

call?

The four conditions for the pid argument of the kill system call are:

 pid is a valid process ID: The process ID is used to identify the process to send a signal to.

 pid is zero: The signal is sent to a group of processes.

 pid is negative: The signal is sent to a group of processes.

 pid does not correspond to any processes or process groups: There are no processes or
process groups that match the pid.

What is the difference between ‘wait’ and ‘waitpid

 wait: Waits for any child process to terminate; simpler but less flexible.

 waitpid: Waits for a specific child process (or any child, based on options); more flexible and
powerful.

If we execute iseek(fd, 0, 2) then what will be the new file byte offset

Iseek

What is broken link

A broken link is a link on a website that no longer works. When you click on it, it leads to a page that
doesn't exist or can't be found. This can happen if the page was deleted or moved.

How to obtain process ID and parent Process ID

 PID: Unique identifier for a running process.

 PPID: Identifier for the parent process that started the current process.

You can use the methods above based on your operating system to find the PID and PPID of any
running process
What is the output of following code?

#include<stdio.h>

#include<unistd.h>

int main( )

if (fork( ) & & (!fork())) {

if (fork( ) || fork( )) {

fork( ); }

printf(“2”);

return 0;

22222222

Q2) Attempt the following

i) What is a process? Draw and Explain state transition diagram of a

process.

A process is a set of instructions that modifies a system's state when it runs. A process's state is
determined by its current activity. A process state transition diagram shows how a process changes
states during its lifecycle

Process States

A process can be in one of several states during its lifecycle. The most common states are:

1. New: The process is being created.

2. Ready: The process is waiting to be assigned to a processor. It is ready to run but is waiting
for CPU time.

3. Running: The process is currently being executed by the CPU.

4. Waiting (Blocked): The process is waiting for some event to occur (like I/O completion) or for
a resource to become available.

5. Terminated: The process has finished execution.


Explain any three data structure for Demand Paging

Here are three key data structures used in demand paging, explained concisely:

1. Page Table

 Purpose: Maps virtual page numbers to physical frame numbers.

 Components: Contains entries for each page, including valid/invalid bits and frame numbers.

 Function: Translates virtual addresses to physical addresses and indicates if a page is in


memory.

2. Frame Table

 Purpose: Tracks the status of physical memory frames.

 Components: Includes frame numbers, process IDs, and the pages currently loaded in each
frame.

 Function: Helps manage memory allocation and determines which page to evict during page
replacement.

3. Swap Space

 Purpose: Disk space used to store pages that are not currently in memory.

 Components: Consists of a swap file or partition and a mapping of pages stored in swap.

 Function: Allows the operating system to free up memory by moving less frequently
accessed pages to disk and retrieving them when needed.

Explain syntax of following system call. [5]

i ) alarm( )

ii) kill( )

iii) sbrk( )

iv ) execl( )

v) fchmod()

 alarm(): Sets an alarm signal after a specified number of seconds.

 kill(): Sends a signal to a process or group of processes.

 sbrk(): Adjusts the heap size of a process.

 execl(): Replaces the current process with a new one (executes a new program).

 fchmod(): Changes the permissions of a file using a file descriptor.


Q3) Attempt the following:

i ) Explain fourth scenario for buffer allocation.

The "fourth scenario" for buffer allocation often refers to "Memory Pool Allocation" or "Fixed-size
Block Allocation."

Key Points:

 Memory Pool: A pre-allocated block of memory divided into fixed-size chunks.

 Efficiency: Reduces fragmentation and speeds up allocation/deallocation since all blocks are
of the same size.

 Use Case: Ideal for systems with predictable memory usage patterns, such as embedded
systems or real-time applications.

 Management: Typically managed using a free list or bitmap to track available blocks.

i) Explain the behaviour of the following C program: [3]

#include<fcntl.h>

main(int argc, char *argv[ ])

int fd, skval;

char c;

if(argc! = 2)

exit( );

while(skval = read(fd, & c, 1))

printf(“char%c\n”, c);

skval=Iseek(fd, 1023L, 1);

printf(“new seek val%d\n”, skval);

1. Command-Line Argument Check:

 The program expects exactly one command-line argument (the name of a file). If the
number of arguments is not equal to 2, it exits.

2. File Opening:
 The program attempts to open the file specified by the command-line argument in
read-only mode (O_RDONLY). If the file cannot be opened (e.g., it doesn't exist), the
program exits.

3. Reading Characters:

 The program enters a while loop that reads one character at a time from the file
using the read function.

 The read function returns the number of bytes read. If it returns a value greater than
0, it means a character was successfully read.

4. Printing Characters:

 For each character read, it prints the character to the standard output.

5. Seeking in the File:

 After printing the character, the program uses lseek to move the file pointer 1023
bytes forward from the current position (SEEK_CUR).

 It prints the new seek position returned by lseek.

6. Loop Continuation:

 The loop continues until read returns 0 (end of file) or a negative value (an error
occurs).

7. Closing the File:

Write a C program to prints the type of file for each command line

Argument

#include <stdio.h>

#include <stdlib.h>

#include <sys/stat.h>

#include <unistd.h>

void print_file_type(const char *filename) {

struct stat file_stat;

// Get file status

if (stat(filename, &file_stat) < 0) {

perror("stat");

return;
}

// Check file type

if (S_ISREG(file_stat.st_mode)) {

printf("%s: Regular file\n", filename);

} else if (S_ISDIR(file_stat.st_mode)) {

printf("%s: Directory\n", filename);

} else if (S_ISCHR(file_stat.st_mode)) {

printf("%s: Character device\n", filename);

} else if (S_ISBLK(file_stat.st_mode)) {

printf("%s: Block device\n", filename);

} else if (S_ISFIFO(file_stat.st_mode)) {

printf("%s: FIFO (named pipe)\n", filename);

} else if (S_ISLNK(file_stat.st_mode)) {

printf("%s: Symbolic link\n", filename);

} else if (S_ISSOCK(file_stat.st_mode)) {

printf("%s: Socket\n", filename);

} else {

printf("%s: Unknown file type\n", filename);

int main(int argc, char *argv[]) {

if (argc < 2) {

fprintf(stderr, "Usage: %s <file1> <file2> ... <fileN>\n", argv[0]);

return EXIT_FAILURE;

for (int i = 1; i < argc; i++) {

print_file_type(argv[i]);

}
return EXIT_SUCCESS;

Q4) Attempt the following:

What are pipes? Explain named pipes and unnamed pipes?

 Unnamed Pipes: Temporary, used between related programs, and disappear when the
programs end.

 Named Pipes: Permanent, can be used by any programs, and stay in the file system until
deleted.

In simple terms, pipes are like communication channels that help programs talk to each other, either
temporarily or permanently

Which operation are performed by the kernel during execution of

fork( )

During the execution of fork(), the kernel performs the following operations:

1. Create PCB: Allocates a new Process Control Block for the child.

2. Duplicate Memory: Copies the parent's memory space (using Copy-On-Write).

3. Assign PID: Gives the child a unique Process ID.

4. Set PPID: Sets the child's Parent Process ID to the parent's PID.

5. Copy File Descriptors: Inherits open file descriptors from the parent.

6. Return Values: Returns PID to the parent and 0 to the child (or -1 on error).

7. Schedule: May schedule the child process for execution.

W rite a C program to demonstrate race condition in catching signals.

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <signal.h>

#include <sys/types.h>

#include <sys/wait.h>

volatile sig_atomic_t shared_var = 0; // Shared variable


// Signal handler

void signal_handler(int signum) {

// Simulate a race condition by incrementing shared_var

for (int i = 0; i < 100000; i++) {

shared_var++;

int main() {

pid_t pid;

// Set up the signal handler

signal(SIGUSR1, signal_handler);

// Create a child process

pid = fork();

if (pid < 0) {

perror("fork failed");

exit(EXIT_FAILURE);

if (pid == 0) { // Child process

// Give the parent time to set up the signal handler

sleep(1);

// Send signal to parent

kill(getppid(), SIGUSR1);

exit(0);

} else { // Parent process

// Wait for the child to finish


wait(NULL);

// Print the final value of shared_var

printf("Final value of shared_var: %d\n", shared_var);

return 0;

Q5) Attempt the following

Under which circumstances the process is swapped out?

A process is swapped out when:

1. Low Memory: The system is running out of RAM.

2. Idle: The process is not doing anything for a while.

3. Low Priority: Other higher-priority processes need more memory.

4. System Demand: A new program needs more memory than is available.

5. Memory Management: The operating system decides to free up space for active processes.

In simple terms, a process gets swapped out when the system needs to make room for other tasks.

Explain the structure of regular file with suitable diagram?

A regular file is a basic type of file used to store data on a computer. It can contain text, images, or
any other type of data. Here’s a simple explanation of its structure:

Structure of a Regular File

1. Header: This part contains metadata about the file, such as:

 File name

 File size

 Creation date

 Last modified date

 Permissions (who can read, write, or execute the file)

2. Data Area: This is the main part of the file where the actual content is stored. It can be:

 Text (like a document)

 Binary data (like an image or executable file)

3. End of File (EOF): This marks the end of the file's data. It tells the system that there is no
more data to read.

4.
Q6) Attempt the following:

Draw and explain the structure of buffer pool?

A buffer pool is a memory area that temporarily holds data that is being read from or written to disk.
It helps improve performance by reducing the number of disk accesses, which are slower than
accessing data in memory.

+-------------------+

| Buffer Frame 1 | <-- Contains data block 1

| (Dirty Bit) |

| (Reference Bit) |

+-------------------+

| Buffer Frame 2 | <-- Contains data block 2

| (Dirty Bit) |

| (Reference Bit) |

+-------------------+

| Buffer Frame 3 | <-- Contains data block 3

| (Dirty Bit) |

| (Reference Bit) |

+-------------------+

| ... |

+-------------------+

| Buffer Frame N | <-- Contains data block N

| (Dirty Bit) |

| (Reference Bit) |

Explanation of the Structure

1. Buffer Frames:

 The buffer pool consists of multiple buffer frames. Each frame can hold a block of
data from the disk. The number of frames can vary based on the system's memory
capacity.

2. Data Blocks:

 Each buffer frame contains a data block, which is a chunk of data read from the disk.
This could be a page of data or a row from a table.

3. Status Information:
 Each buffer frame has additional information:

 Dirty Bit: This indicates whether the data in the frame has been modified
(dirty) and needs to be written back to the disk. If the dirty bit is set, it
means the data in that frame is different from what is on the disk.

 Reference Bit: This indicates whether the frame has been accessed recently.
It helps the DBMS decide which frames to keep in memory and which to
evict when new data needs to be loaded.

4. Replacement Policy:

 When the buffer pool is full and new data needs to be loaded, a replacement
policy (like LRU - Least Recently Used) determines which buffer frame to evict. This
policy helps manage memory efficiently.

Draw and explain Unix System architecture.

Explanation of Components

The Unix operating system is made up of four main layers that define how the hardware and user
interact:

 Hardware layer

Contains the hardware-related information needed for the Unix environment to function

 Kernel layer

The core of the operating system, which acts as an interface between the hardware and the user

 Shell layer

Interprets command line input and calls the necessary programs to do the work

 Applications layer

Contains user commands and applications

Q7) Attempt the following:

Write a short note on process context

Process context is the information that defines the state of a process in an operating system. It
includes:

1. Process ID (PID): Unique identifier for the process.

2. Program Counter (PC): Address of the next instruction to execute.

3. Registers: CPU registers that hold temporary data and state information.

4. Memory Management Information: Details about memory allocation, including page tables
and segment information.

5. Process State: Current status of the process (e.g., running, waiting, terminated).

6. I/O Status Information: Information about I/O devices allocated to the process.
What is anonymous memory mapping? What are the advantages ofallocating memory via
anonymous memory mapping?

Anonymous memory mapping is a method of allocating memory in a process without associating it


with any file. This is typically done using system calls like mmap with the MAP_ANONYMOUS flag.

Advantages:

1. Isolation: Memory is private to the process, preventing other processes from accessing it.

2. Efficiency: Reduces overhead by avoiding file I/O; memory is allocated directly from the
system.

3. Flexibility: Allows for dynamic memory allocation without needing to manage file-backed
storage.

4. Zero Initialization: Memory is often initialized to zero, which can simplify certain
programming tasks.

5. Easy Cleanup: Memory can be easily released when no longer needed, reducing
fragmentation.

Overall, anonymous memory mapping provides a fast and efficient way to manage memory for
applications

You might also like