1. Explain
the services of Operating System in detail
Answer:
Operating
systems plays a very vital role for providing services in two different
sectors:-
- User
- System
Following are the six services provided by operating systems to the convenience of the users.
1. User
interface:
Almost
all operating systems have a user interface (UT). This interface can take
several forms.
- One is a DTrace Command Line Interface, which uses text commands and a method for entering them (say, a program to allow entering and editing of commands).
- Another is a Batch Interface, in which commands and directives to control those commands are entered into files, and those files are executed.
- Most commonly, a Graphical User Interface (GUI) is used. Here, the interface is a window system with a pointing device to direct I/O, choose from menus, and make selections and a keyboard to enter text. Some systems provide two or all three of these variations.
2. Program
Execution
- The purpose of computer systems is to allow the user to execute programs. So the operating system provides an environment where the user can conveniently run programs. Running a program involves the allocating and deallocating memory, CPU scheduling in case of multiprocessing.
3. I/O
Operations
- Each program requires an input and produces output. This involves the use of I/O. So the operating systems are providing I/O makes it convenient for the users to run programs.
4. File
System Manipulation
- The output of a program may need to be written into new files or input taken from some files. The operating system provides this service.
5. Communications
- The processes need to communicate with each other to exchange information during execution. It may be between processes running on the same computer or running on the different computers. Communications can occur in two ways:
- shared memory or
- message passing
6. Error
Detection
- An error is one part of the system may cause malfunctioning of the complete system. To avoid such a situation operating system constantly monitors the system for detecting the errors. This relieves the user of the worry of errors propagating to various part of the system and causing malfunctioning.
Figure:
A view of operating system services
Following
are the three services provided by operating systems for ensuring the efficient
operation of the system itself.
1. Resource
allocation
- When multiple users are logged on the system or multiple jobs are running at the same time, resources must be allocated to each of them. Many different types of resources are managed by the operating system and they include
- CPU
- Memory
- I/O Devices
- Files
Proper
Resource allocation helps to increase throughput, efficiency and reduces
turnaround time of the system.
2. Accounting
- The operating systems keep track of which users use how many and which kinds of computer resources. This record keeping may be used for accounting (so that users can be billed) or simply for accumulating usage statistics.
3. Protection
- When several disjointed processes execute concurrently, it should not be possible for one process to interfere with the others, or with the operating system itself. Protection involves ensuring that all access to system resources is controlled. Security of the system from outsiders is also important. Such security starts with each user having to authenticate him to the system, usually by means of a password, to be allowed access to the resources.
Services
of OS also includes System calls
1. System
Call
- System calls provide an interface between the process and the operating system.
- System calls allow user-level processes to request some services from the operating system which process itself is not allowed to do.
- For example, for I/O a process involves a system call telling the operating system to read or write particular area and this request is satisfied by the operating system.
Answer: Computer system can be divided into four components
Hardware – provides basic computing resources
- CPU
- Memory
- I/O devices
Operating
system
Controls and coordinates use of hardware among various applications and users
Application
programs
Define the ways in which the system resources are used to solve the computing problems of the users
- Word processors
- Compilers
- Web browsers
- Database systems
- Video games
Users
- People
- Machines
- Other Computer
Figure:
Abstract view of the components of a computer system
We
can also view a computer system as consisting of hardware/ software/ and data.
The operating system provides the means for proper use of these resources in
the operation of the computer system. An operating system is similar to a
government. Like a government, it performs no useful function by itself. It
simply provides an environment within which other programs can do useful work.
User
View
- The user's view of the computer varies according to the interface being used. Most computer users sit in front of a PC, consisting of a monitor/ keyboard/ mouse, and system unit. Such a system is designed for one user to monopolize its resources. The goal is to maximize the work (or play) that the user is performing.
- In this case/ the operating system is designed mostly for ease of use with some attention paid to performance and none paid to resource utilization how various hardware and software resources are shared.
- Some computers have little or no user view. For example, embedded computers in home devices and automobiles may have numeric keypads and may turn indicator lights on or off to show status, but they and their operating systems are designed primarily to run without user intervention.
System
View
- From the computer's point of view, the operating system is the program most intimately involved with the hardware. In this context, we can view an operating system as a resource allocator.
- A computer system has many resources that may be required to solve a problem: CPU time, memory space, file-storage space, I/0 devices, and so on. The operating system acts as the manager of these resources.
- A slightly different view of an operating system emphasizes the need to control the various I/0 devices and user programs. Hence an operating system is also called as control program. A Control Program manages the execution of user programs to prevent errors and improper use of the computer. It is especially concerned with the operation and control of I/O devices.
Answer:
- Each process is represented in the operating system by a process control block (PCB) also called a task control block. A PCB is shown in Figure below. It contains many pieces of information associated with a specific process, including these:
Process
state:
- The state may be new, ready, running, waiting, halted, and So on.
Program
counter:
- The counter indicates the address of the next instruction to be executed for this process.
CPU
registers:
- The registers vary in number and type, depending on the computer architecture. They include accumulators, index registers, stack pointers, and general-purpose registers, plus any condition-code information. Along with the program counter, this state information must be saved when an interrupt occurs, to allow the process to be continued correctly afterward.
CPU-scheduling
information:
- This information includes a process priority, pointers to scheduling queues, and any other scheduling parameters. For Example which scheduling algorithm is used whether it’s preemptive or non-preemptive?
Memory-management information:
- This information may include such information as the value of the base and limit registers, the page tables, or the segment tables, depending on the memory system used by the operating system
Accounting
information:
- This information includes the amount of CPU and real time used, time limits, account numbers, job or process numbers, and so on.
I/O
Status information:
- The information includes the list of I/O devices allocated to this process, a list of open files, and so on.
CPU
Switch from Process to Process:
- PCB saves the data when process undergoes Context switching. Context switching process takes place in preemption, when the current executing process is asked to wait as other high priority/scheduled process need the CPU (execution). The status of currently executing process is stored in register (PCB) and resources are handed to the new process.
4. What is Process? Explain Process State Diagram in brief.
Answer
What
is Process?
A
process is a program in execution.
- A process is more than the program code, which is sometimes known as the text section. It also includes the current activity, as represented by the value of the program counter and the contents of the processor's registers. In addition, a process generally includes the process stack, which contains temporary data (such as method parameters, return addresses, and local variables), and a data section, which contains global variables.
- New State: The process is being created. In this state the process is just created and publishes the list of resources needed to complete its execution.
- Running State: A process is said to be running if it has the CPU, that is, process actually using the CPU at that particular instant. An executing process can be sent to three different state from the Running state:
- Terminate (If the process completes the execution, it will go to terminate state)
- Waiting (When an executing process demands for I/O or an interrupt occurs then it will go to waiting state)
- Ready (When the process is preempted, it will go back to the ready state)
- Blocked (or waiting) State: A process is said to be blocked if it is waiting for some event to happen such that as an I/O completion before it can proceed. Note that a process is unable to run until some external event happens.
- Ready State: A process is said to be ready if it needs a CPU to execute. A ready state process is runnable but temporarily stopped running to let another process run.
- Terminated state: The process has finished execution.
5. What is thread? What are the benefits of multi-threaded programming? Explain the user level and kernel threads in brief
Answer:
Thread: A thread, sometimes called a lightweight process (LWP), is a basic unit of CPU utilization; it comprises a thread ID, a program counter, a register set, and a stack.
It
shares with other threads belonging to the same process its code section, data
section, and other operating-system resources, such as open files and signals.
A
traditional (or heavyweight) process has a single thread of control. If the
process has multiple threads of control, it can do more than one task at a
time.
Example:
A web browser might have one thread display images or text while another thread
retrieves data from the network. A word processor may have a thread for
displaying graphics, another thread for reading keystrokes from the user, and a
third thread for performing spelling and grammar checking in the background.
In
certain situations a single application may be required to perform several
similar tasks.
For example, a web server accepts client requests for web pages, images, sound, and so forth.
A busy web server may have several (perhaps hundreds) of clients
concurrently accessing it. If the web server ran as a traditional single
threaded process, it would be able to service only one client at a time.
Figure:
Single-threaded and multithreaded
The benefits
of multithreaded programming can be broken down into four major categories:
- Responsiveness: Multithreading an interactive application may allow a program to continue running even if part of it is blocked or is performing a lengthy operation, thereby increasing responsiveness to the user. For instance, a multithreaded web browser could still allow user interaction in one thread while an image is being loaded in another thread.
- Resource sharing: By default, threads share the memory and the resources of the process to which they belong. The benefit of code sharing is that it allows an application to have several different threads of activity all within the same address space.
- Economy: Allocating memory and resources for process creation is costly. Alternatively, because threads share resources of the process to which they belong, it is more economical to create and context switch threads. In Solaris 2, creating a process is about 30 times slower than is creating a thread, and context switching is about five times slower.
- Utilization of multiprocessor architectures: The benefits of multithreading can be greatly increased in a multiprocessor architecture, where each thread may be running in parallel on a different processor. A single threaded process can only run on one CPU, no matter how many are available.
The
OS supports the threads that can provided in following two levels:
User-Level
Threads
User-level
threads implement in user-level libraries, rather than via systems calls, so
thread switching does not need to call operating system and to cause interrupt
to the kernel. In fact, the kernel knows nothing about userlevel threads and
manages them as if they were single-threaded processes. Advantages:
- User-level threads do not require modification to operating systems.
- Simple Representation: Each thread is represented simply by a PC, registers, stack and a small control block, all stored in the user process address space.
- Simple Management: This simply means that creating a thread, switching between threads and synchronization between threads can all be done without intervention of the kernel.
- Fast and Efficient: Thread switching is not much more expensive than a procedure call.
Disadvantages:
- There is a lack of coordination between threads and operating system kernel.
- User-level threads require non-blocking systems call i.e., a multithreaded kernel.
Kernel-Level
Threads
In
this method, the kernel knows about and manages the threads. Instead of thread
table in each process, the kernel has a thread table that keeps track of all
threads in the system. Operating Systems kernel provides system call to create
and manage threads.
Advantages:
- Because kernel has full knowledge of all threads, Scheduler may decide to give more time to a process having large number of threads than process having small number of threads.
- Kernel-level threads are especially good for applications that frequently block.
Disadvantages:
- The kernel-level threads are slow and inefficient. For instance, threads operations are hundreds of times slower than that of user-level threads.
- Since kernel must manage and schedule threads as well as processes. It requires a full thread control block (TCB) for each thread to maintain information about threads. As a result there is significant overhead and increased in kernel complexity.
Multithreading
Models
Many
systems provide support for both user and kernel threads, resulting in
different multithreading models. We look at three common types of threading
implementation.
Many-to-One
Model
The
many-to-one model maps many user-level threads to one kernel thread. Thread
management is done in user space, so it is efficient, but the entire process
will block if a thread makes a blocking system call. Also, because only one
thread can access the kernel at a time, multiple threads are unable to run in
parallel on multiprocessors.
One-to-one
Model
The
one-to-one model maps each user thread to a kernel thread. It provides more
concurrency than the many-toone model by allowing another thread to run when a
thread makes a blocking system call; it also allows multiple threads to run in
parallel on multiprocessors. The only drawback to this model is that creating a
user thread requires creating the corresponding kernel thread. Windows NT,
Windows 2000, and OS/2 implement the one-to-one model.
Many-to-Many
Model
The
many-to-many model multiplexes many user-level threads to a smaller or equal
number of kernel threads. The number of kernel threads may be specific to
either a particular application or a particular machine (an application may be
allocated more kernel threads on a multiprocessor than on a uniprocessor).
Whereas
the many-to-one model allows the developer to create as many user threads as
she wishes, true concurrency is not gained because the kernel can schedule only
one thread at a time. In many-to-many model Developers can create as many user
threads as necessary, and the corresponding kernel threads can run in parallel
on a multiprocessor.
6. What do you mean by lnter Processes Communication? Explain with examples
Answer:
Processes executing concurrently in the
operating system may be either independent processes or cooperating processes.
A process is independent if it cannot affect
or be affected by the other processes executing in the system.
Any process that does not share data with any
other process is independent.
A process is cooperating if it can affect or
be affected by the other processes executing in the system.
Clearly, any process that shares data with
other processes is a cooperating process.
There
are several reasons for providing an environment that allows process
Cooperation:
Information
sharing
Since
several users may be interested in the same piece of information (for instance,
a shared file), we must provide an environment to allow concurrent access to
such information
Computation
speedup
If
we want a particular task to run faster, we must break it into subtasks, each
of which will be executing in parallel with the others. Notice that such a
speedup can be achieved only if the computer has multiple processing elements
(such as CPUs or I/O channels).
Modularity
We
may want to construct the system in a modular fashion, dividing the system
functions into separate processes or threads
Convenience
Even
an individual user may work on many tasks at the same time. For instance, a
user may be editing, printing, and compiling in parallel.
Cooperating
processes require an Interprocess communication (IPC) mechanism that will allow
them to exchange data and information.
There are two fundamental models of Interprocess communication:
1) Shared
Memory
In the shared-memory model, a region of memory that is shared by cooperating processes is established. Processes can then exchange information by reading and writing data to the shared region.
2) Message Passing
In
the message passing model, communication takes place by means of messages
exchanged between the cooperating processes.
IPC
facility provides two operations:
- send(message) – message size fixed or variable
- receive(message)
If P
and Q wish to communicate, they need to:
- establish a communication link between them
- exchange messages via send/receive
Direct
Communication
Processes
must name each other explicitly:
receive(Q, message) – receive a message from process Q
- Links are established automatically.
- A link is associated with exactly one pair of communicating processes.
- Between each pair there exists exactly one link.
- The link may be unidirectional, but is usually bi-directional.
Indirect
Communication
Messages
are directed and received from mailboxes (also referred to as ports).
- Each mailbox has a unique id.
- Processes can communicate only if they share a mailbox.
Figure:
Communications models. (a) Message passing. (b) Shared memory.
Shared-Memory
Systems
Interprocess communication using shared memory
requires communicating processes to establish a region of shared memory. Typically,
a shared-memory region resides in the address space of the process creating the
shared memory segment.
Other processes that wish to communicate using
this shared memory segment must attach it to their address space.
Shared memory requires that two or more
processes agree to remove this restriction. They can then exchange information
by reading and writing data in the shared areas.
The processes are also responsible for
ensuring that they are not writing to the same location simultaneously.
Message-Passing
Systems
Message passing provides a mechanism to allow processes to communicate and to synchronize their actions without sharing the same address space and is particularly useful in a distributed environment, where the communicating processes may reside on different computers connected by a network.
For example, a chat program used on the World Wide Web could be designed so that chat participants communicate with one another by exchanging messages.
A message-passing facility provides at least
two operations: send (message) and receive (message).
Messages sent by a process can be of either fixed or variable size. If only fixed-sized messages can be sent, the system-level implementation is straightforward.
If processes P and Q want to communicate, they must send messages to and receive messages from each other; a communication link must exist between them. This link can be implemented in a variety of ways like-
o Synchronous or asynchronous communication
o Automatic or explicit buffering
7. Differentiate between: a) Thread & Process b) Process & Program
Answer
Process |
Thread |
1. Process cannot share the same memory
area (address space) |
1. Threads can share memory and files. |
2. It takes more time to create a process
|
2. It takes less time to create a thread.
|
3. It takes more time to complete the
execution and terminate. |
3. Less time to terminate. |
4. Execution is very slow. |
4. Execution is very fast. |
5. It takes more time to switch between
two processes. |
5. It takes less time to switch between
two threads. |
6.System calls are required to
communicate each other |
6. System calls are not required. |
7. It requires more resources to execute.
|
7. Requires fewer resources. |
8. Implementing the communication between
processes is bit more difficult. |
8.Communication between two threads are
very easy to implement because threads share the memory |
Both
are same beast with different name or when this beast is sleeping (not executing)
it is called program and when it is executing becomes process.
Process |
Program |
1. Process is defined as program under
execution. |
1. Program is a set of instructions
written to perform a specific task which executes in a sequential fashion. |
2. A process is expressed in assembly
language or machine language. |
2. A program is an algorithm expressed in
programming language |
3. Process is a dynamic object |
3. Program is a static object |
4. Process loaded in to main memory |
4. Process loaded in to main memory |
5. Process is an active entity. |
5. Program is a passive entity |
6. Time span of process is limited |
6. Time span of program is unlimited |