0% found this document useful (0 votes)
117 views15 pages

Unit Test Question Bank

Uploaded by

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

Unit Test Question Bank

Uploaded by

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

Question Bank for Unit test 1

1. Explain different types of OS


Ans:
Batch Operating system: It is one of the important type of operating system.
The users who using a batch operating system do not interact with the computer
directly. Each user prepares its job on an off-line device like punch cards and submits it
to the computer operator.
Time shared operating system: It uses CPU scheduling and multi-programming to
provide each with a small portion of a shared computer at once. Each user has at least
one separate program in memory. A program loaded into memory and executes, it
performs a short period of time either before completion or to complete I/O. This short
period of time during which user gets attention of CPU is known as time slice, time slot
or quantum.
Embedded operating system: It is a specialized operating system (OS) designed to
perform a specific task for a device that is not a computer. The main job of an
embedded OS is to run the code that allows the device to do its job.
Multiprogramming OS: it is an ability of an operating system that executes more than
one program using a single processor machine. More than one task or program or jobs
are present inside the main memory at one point of time.
A network operating system (NOS): is a computer operating system (OS) that is
designed primarily to support workstations, personal computers and, in some
instances, older terminals that are connected on a local area network (LAN).
A distributed operating system: it is system software over a collection of independent
software, networked, communicating, and physically separate computational nodes.
They handle jobs which are serviced by multiple CPUs. Each individual node holds a
specific software subset of the global aggregate operating system.
Multiprocessor Operating system: Multiprocessor system means, there are more
than one processor which work parallel to perform the required operations. It allows the
multiple processors, and they are connected with physical memory, computer buses,
clocks, and peripheral devices.
Real-time operating systems (RTOS): these are used in environments where a large
number of events, mostly external to the computer system, must be accepted and
processed in a short time or within certain deadlines. such applications are industrial
control, telephone switching equipment, flight control, and real-time simulations. With
an RTOS, the processing time is measured in tenths of seconds. This system is
time-bound and has a fixed deadline. The processing in this type of system must occur
within the specified constraints. Otherwise, This will lead to system failure.
Examples of the real-time operating systems: Airline traffic control systems, Command
Control Systems, Airlines reservation system, Heart Pacemaker, Network Multimedia
Systems, Robot etc.
The real-time operating systems can be of 3 types –
Hard Real-Time operating system
Soft real-time operating system
Firm Real-time Operating System

2. Explain monolithic and microkernel architecture


Ans:
3. Write a short note on Shell scripting
Ans:
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. The shell is the operating system's
command-line interface (CLI) and interpreter for the set of commands that are
used to communicate with the system.

A shell script is usually created for command sequences in which a user has a
need to use repeatedly in order to save time. Like other programs, the shell
script can contain parameters, comments and subcommands that the shell
must follow. Users initiate the sequence of commands in the shell script by
simply entering the file name on a command line.

Types of shells
In Unix and Linux, the two major types of shell scripts are:

- Bourne again shells (BASH)- BASH is the default shell for Unix version 7.
The character for prompting a bourne again shell is $.

- C shells- A C shell is run in a text terminal window and is able to easily read
file commands. The character for prompting a C shell is %.

Using a shell script is most useful for repetitive tasks that may be time
consuming to execute by typing one line at a time. A few examples of
applications shell scripts can be used for include:
• Automating the code compiling process.

• Running a program or creating a program environment.

• Completing batch

• Manipulating files.

• Linking existing programs together.

• Executing routine backups.

• Monitoring a system.
Advantages and disadvantages of shell scripts
Shell scripting is meant to be simple and efficient. It uses the same syntax in
the script as it would on the shell command line, removing any interpretation
issues. Writing code for a shell script is also faster and requires less of
learning curve than other programming languages.

However, if there is an error in a shell script, this can prove to be extremely


costly if left unnoticed. Additionally, differing platforms associated with shell
scripting may not be compatible. Shell scripts can also be slower to execute
than individual commands.

4. Define process and its states


Ans: A process is a program in execution and it is more than a program code called
as text section and this concept works under all the operating system because all
the task perform by the operating system needs a process to perform the task.

The process executes when it changes the state. The state of a process is defined by
the current activity of the process.
Each process may be in any one of the following states −
• New − The process is being created.
• Running − In this state the instructions are being executed.
• Waiting − The process is in waiting state until an event occurs like I/O operation
completion or receiving a signal.
• Ready − The process is waiting to be assigned to a processor.
• Terminated − the process has finished execution.
• It is important to know that only one process can be running on any processor at
any instant. Many processes may be ready and waiting.

Explanation
Step 1 − Whenever a new process is created, it is admitted into ready state.
Step 2 − If no other process is present at running state, it is dispatched to running
based on scheduler dispatcher.
Step 3 − If any higher priority process is ready, the uncompleted process will be sent to
the waiting state from the running state.
Step 4 − Whenever I/O or event is completed the process will send back to ready state
based on the interrupt signal given by the running state.
Step 5 − Whenever the execution of a process is completed in running state, it will exit
to terminate state, which is the completion of process.

5. State the structure of process


Ans:
• New (Create) – In this step, the process is about to be created but not yet
created, it is the program which is present in secondary memory that will
be picked up by OS to create the process.
• Ready – New -> Ready to run. After the creation of a process, the process
enters the ready state i.e. the process is loaded into the main memory. The
process here is ready to run and is waiting to get the CPU time for its
execution. Processes that are ready for execution by the CPU are
maintained in a queue for ready processes.
• Run – The process is chosen by CPU for execution and the instructions
within the process are executed by any one of the available CPU cores.
• Blocked or wait – Whenever the process requests access to I/O or needs
input from the user or needs access to a critical region(the lock for which is
already acquired) it enters the blocked or wait state. The process continues
to wait in the main memory and does not require CPU. Once the I/O
operation is completed the process goes to the ready state.
• Terminated or completed – Process is killed as well as PCB is deleted.
• Suspend ready – Process that was initially in the ready state but was
swapped out of main memory(refer Virtual Memory topic) and placed onto
external storage by scheduler is said to be in suspend ready state. The
process will transition back to ready state whenever the process is again
brought onto the main memory.
• Suspend wait or suspend blocked – Similar to suspend ready but uses the
process which was performing I/O operation and lack of main memory
caused them to move to secondary memory. When work is finished it may
go to suspend ready.
6. Explain multithreading and P threads
Ans:
Multithreading is the ability of a program or an operating system to enable more
than one user at a time without requiring multiple copies of the program
running on the computer. Multithreading can also handle multiple requests from
the same user.

PThreads is a highly concrete multithreading system that is the UNIX system’s


default standard. PThreads is an abbreviation for POSIX threads, and POSIX is
an abbreviation for Portable Operating System Interface, which is a type of
interface that the operating system must implement.
7. Explain synchronization in threads
Ans:

Synchronization is the cooperative act of two or more threads that ensures that each
thread reaches a known point of operation in relationship to other threads before
continuing. Attempting to share resources without correctly using synchronization is the
most common cause of damage to application data.
Typically, synchronizing two threads involves the use of one or more synchronization
primitives. Synchronization primitives are low-level functions or application objects
(not IBM® i objects) that your application uses or creates to provide the synchronization
behavior that the application requires.
Here are the most common synchronization primitives in order of least to most
computationally expensive:
• Compare and swap

• Mutual exclusion (mutexes) and threads

• Semaphores and threads

• Condition variables and threads

• Threads as synchronization primitives

• Space location locks

• Object locks
8. Define kernel and user space
Ans:
Kernel space is strictly reserved for running a privileged operating system kernel, kernel
extensions, and most device drivers. In contrast, user space is the memory area
where application software and some drivers execute.

The term user space (or userland) refers to all code that runs outside the operating system's
kernel.[1] User space usually refers to the various programs and libraries that the operating system
uses to interact with the kernel: software that performs input/output, manipulates file
system objects, application software, etc.

Each user space process normally runs in its own virtual memory space, and, unless explicitly
allowed, cannot access the memory of other processes. This is the basis for memory protection in
today's mainstream operating systems, and a building block for privilege separation. A separate user
mode can also be used to build efficient virtual machines – see Popek and Goldberg virtualization
requirements. With enough privileges, processes can request the kernel to map part of another
process's memory space to its own, as is the case for debuggers. Programs can also request shared
memory regions with other processes, although other techniques are also available to
allow inter-process communication.
9. Explain process creation in Unix
Ans:
Process creation is achieved through the fork() system call. The newly created process is
called the child process and the process that initiated it (or the process when execution is
started) is called the parent process. After the fork() system call, now we have two
processes - parent and child processes.

After creation of the child process,

#include <sys/types.h>
#include <unistd.h>

pid_t fork(void);

program:
File name: basicfork.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main() {
fork();
printf("Called fork() system call\n");
return 0;
}
10.Define zombie, orphan for a process
Ans:

Zombie Process :
A Zombie is a process that has completed its task but still, it shows an entry in
a process table. The zombie process usually occurred in the child process. Very
short time the process is a zombie. After the process has completed all of its
tasks it reports the parent process that it has about to terminate.
Zombie process states always indicated by Z.
The zombie process has controlling terminals.
The zombie process treated as dead they are not used for system processing.
To remove the zombie process execute the kill command.
Orphan Process :
A child process that remains running even after its parent process is
terminated or completed without waiting for the child process execution is
called an orphan. A process becomes an orphan unintentionally. Some time
intentionally becomes orphans due to long-running time to complete the
assigned task without user attention. The orphan process has controlling
terminals.
The orphan process was created unknowingly due to a system crash.
Orphan The zombie process has controlling terminals.
An orphan process is a computer process even after their parent terminates
init is become a parent and continue the remaining task.
Terminate the Orphan process use the SIGHUP signal.
11.Define Mutex and its syntax and its operations.
Ans:
Mutex is a mutual exclusion object that synchronizes access to a resource. It is created with
a unique name at the start of a program. The Mutex is a locking mechanism that makes sure
only one thread can acquire the Mutex at a time and enter the critical section.

• A Mutex is a lock that we set before using a shared resource and release
after using it.
• When the lock is set, no other thread can access the locked region of code.
• So we see that even if thread 2 is scheduled while thread 1 was not done
accessing the shared resource and the code is locked by thread 1 using
mutexes then thread 2 cannot even access that region of code.
• So this ensures synchronized access of shared resources in the code.

Working of a mutex:
Suppose one thread has locked a region of code using mutex and is executing
that piece of code.
Now if scheduler decides to do a context switch, then all the other threads
which are ready to execute the same region are unblocked.
Only one of all the threads would make it to the execution but if this thread
tries to execute the same region of code that is already locked then it will
again go to sleep.
Context switch will take place again and again but no thread would be able to
execute the locked region of code until the mutex lock over it is released.
Mutex lock will only be released by the thread who locked it.
So this ensures that once a thread has locked a piece of code then no other
thread can execute the same region until it is unlocked by the thread who
locked it.
Syntax:
1. int pthread_mutex_init(pthread_mutex_t *restrict mutex, const
pthread_mutexattr_t *restrict attr) : Creates a mutex, referenced by mutex,
with attributes specified by attr. If attr is NULL, the default mutex attribute
(NONRECURSIVE) is used.
Returned value
If successful, pthread_mutex_init() returns 0, and the state of the mutex
becomes initialized and unlocked.
If unsuccessful, pthread_mutex_init() returns -1.
2. int pthread_mutex_lock(pthread_mutex_t *mutex) : Locks a mutex object,
which identifies a mutex. If the mutex is already locked by another thread,
the thread waits for the mutex to become available. The thread that has
locked a mutex becomes its current owner and remains the owner until the
same thread has unlocked it. When the mutex has the attribute of
recursive, the use of the lock may be different. When this kind of mutex is
locked multiple times by the same thread, then a count is incremented and
no waiting thread is posted. The owning thread must call
pthread_mutex_unlock() the same number of times to decrement the
count to zero.
Returned value
If successful, pthread_mutex_lock() returns 0.
If unsuccessful, pthread_mutex_lock() returns -1.
int pthread_mutex_unlock(pthread_mutex_t *mutex)
int pthread_mutex_destroy(pthread_mutex_t *mutex)

You might also like