Monday, 24 August 2020

Concept of a Process in Operating System (OS):

Concept of a Process in OS: 

When an OS runs a program, it is loaded into memory and the control is transferred to the first instruction of that program. After that, the program starts to run. A process can be defined as a program in execution. It is used as a unit of work for a processor. Every process has a program counter (PC), a stack, data section, etc. Furthermore, there can be multiple processes associated with one program. As such, a process is more than a program.

 

A process consists of components like:

Object program - object program i.e. code to be executed.

Data - data is used for executing the program.

Resources - while executing the program, it may require some resources.

Status - to verify the status of process execution.

 

The common attributes of a process consists of the hardware state, memory, CPU and the progress (execution status) of that process. Another important consideration is that a program is called a passive entity, while a process is an active entity. A program becomes process when, executable file is loaded into memory.

 

A process is more than a program code. This program code is generally called as the text section. A data section contains global variables and the heap contains memory that is dynamically allocated during runtime. Whereas, a stack usually has temporary data like temporary variables, local variables, function or subroutine parameters, return addresses, etc. In cases, a same program may have two or more processes that are associated with it. But, they are not considered as separate execution sequences. A program can create multiple processes. For ex: a web browser application.


 Process vs. Programs:


Process vs. Program

Process States:

Whenever a process executes, there occurs change in its state. Usually, a process state is determined by the current activity of the process. Each process may be in one of the following states:

 

1.    New: the process has just been created.

2.    Running: the process is currently being executed.  A running process has all the resources that are needed for its execution, including the processor.

3.    Waiting: the process is waiting for some event to occur. A running process may become suspended by invoking an IO routine.

4.    Ready: the process is waiting to be assigned to a processor allocated to them by OS so that it can run.

5.    Terminate: the process has finished its execution and no longer requires CPU.

 

Whenever a process changes its state, an OS updates the process PCB (Process Control Block) in the list that corresponds to its new state. Only one process can be running in any processor at any time. However, there can be many processes in ready and waiting states.  Processes that are in ready state are loaded into a ready queue. A ready queue is a one type of data structure used by an OS to store the processes.


Process states


Transitions of Process States:

New➔Ready:  an OS creates a process and prepares it to be executed. After that OS moves the process into the ready queue.


Ready➔Running: when it is a time to select a process to run, OS selects one of the jobs from the ready queue and move the process from ready state to running state.


Running➔Terminated: when a process completes its execution, then the OS terminates that process from running state. An OS may terminate a process because of some other reasons too. Some possible reasons are time limit exceeded, memory unavailable, access violation, protection error, IO failure, etc.


Running➔Ready: an OS shifts a running process to a ready state when the time slot of the processor expires or it receives an interrupt signal.  Consider an example, suppose process P1 is being executed by processor. Meanwhile, a process P2 generates an interrupt signal to processor. In this case, the processor first compares the priorities of processes P1 and P2.  If P1>P2, then the processor continues the process P1. Otherwise, processor switches to process P2 and the process P1 is moved to the ready state.


Running➔Waiting: if a process requires some event to occur for its completion or if there is an IO device requirement, in such cases a process is put into waiting state. Whenever, an OS cannot not provide IO or that event immediately, a process is moved to waiting state by the OS.


Waiting➔Ready:  a process which is in the blocked state is moved to ready state when the event for which it has been waiting occurs.  For ex: a process is in running state, it need an IO device, then the process moved to blocked or waiting state. Now, when the IO device is provided by OS, the process is moved to ready state from waiting or blocked state.



Tuesday, 18 August 2020

Data models in DBMS and differences between Relational, Network and Hierarchical models

 Various Data Models in DBMS:

 

 Data Model:

A data model is a collection of conceptual tools for describing data - its relationships, semantics and consistency constraints. Data models can be distinguished from one another on the basis of the relationship among data, that is defined and the way the data is conceptually defined.

A primary objective that a data model serves is to evolve a high level data model. It should assist the designer to incorporate a major portion of semantics of database in the schema.

In DBMS, the data models are broadly classified as:

1.    Object based data models

2.    Record based data models and;

3.    Physical data models

 

1.    Object Based Data Models:

These models are used in describing data at a logical and view level. They have properties like they provide flexible structure in the capabilities and allow us to specify data constraints explicitly. This model highlights that everything is object having set of attributes.

 

Examples of data models that fall in this category are:

a)    Entity relationship model

b)    Object oriented model

 

2.    Record Based Data Models:

The record based data models are used to describe data at a logical and view level. However, they revolve around the records of database and specify the overall structure of database with the help of value of records. This is a key distinguishing factor between the record based and object based model.

 

These models have got their name record based models because the database is structured in fixed format records of several types. Each record type defines a fixed number of fields or attributes and each field is usually of a fixed length. This results in simple physical level implementations of the database.

Examples of data models that fall in this category are:

a)    Relational model

b)    Network model

c)    Hierarchical model

 

3.    Physical Data Models:

 

This model is used to describe data at the lowest level. It actually describes the behaviour of data at disk level. Furthermore, it also describes the way data and data relationships that are maintained while storing them on the disk. As such this leads to the way a DBMS is going to use secondary storage devices for storing and accessing data.

 

Examples of data models that fall in this category are:

a)    Unifying model

b)    Frame memory model

 

A.  Network Model:

 

The data in network model are represented by collection of records. The relationships among data are represented by links, which can be viewed as pointers.

Simply speaking, a pointer is a physical address which identifies where the next record can be found on the disk or we can say that it points to the next address location.

 

The network model allows each record to have multiple parent and child records forming a lattice structure. Thus, network model supports many to many relationships. The relationship between different records is called sets. This model is used as an easy way of representing objects and their relationships. Following figure shows an example for network database:


Network database example

B.  Hierarchical Model:

 

This model is very similar to network model, as in both the models, the data and relationships among data are represented by using records and links respectively. In this model, records are organized as collection of trees rather than arbitrary graphs.

 

The data storage is in the form of parent child relationship. An origin of the tree is called the root.  Data that follows the root is called a node and the last node in the series is called as a leaf node. Usually, there is one to many relationship found in this model. Following figure shows an example for hierarchical database:


Hierarchical database example


Differences between Relational, Network and Hierarchical Models:

Parameter

Relational model

Network model

Hierarchical model

Relationship

It supports one to many and many to many relationships.

It supports many to many relationships.

It supports one to many relationships.

Nature

It is a table based model, where a table is a collection of rows and columns.

It is based on records and links.

It is based on tree like structure having one root, several nodes and leaf nodes.

Popularity

This model is more popular.

This model is less popular.

This model is less popular.

Applications

It has many applications, almost unlimited.

It is an upgraded version of hierarchical model, so used in the network.

It is mainly used in mainframe and database system.

Data relation

This model uses values to relate data. It does not use pointers or links.

This model uses links to relate data.

This model uses pointers to relate data.

Storage

The data is stored in the form of tables.

The data is stored in the form of arbitrary graph.

The data is stored in the form of a tree having parent - child relationship.


Tuesday, 11 August 2020

What are 7 essential functions of DBMS?

 

Functions of DBMS:

 

A primary goal of a DBMS is to provide a way to store and retrieve database information in such a way that it should be both convenient and efficient.

 

1.    Data Definition:

 

The data definition tells us that the DBMS must be able to accept data definitions in source form and convert them to appropriate object form. This means, the DBMS must include DDL processor or DDL compiler components for each of the various data definition languages (DDLs).

 

2.    Data Manipulation:

 

The DBMS must be able to handle requests to add new data to the database, retrieve, update, or delete existing data in the database. This means, the DBMS must include DML processor DML compiler components for each of the various data manipulation languages (DMLs).

 

3.    Optimization and Execution:

 

DML requests, whether planned or unplanned, must be processed by the optimizer component whose purpose is to determine an efficient way of implementing the request. These optimized requests are then executed under the control of runtime manager.

 

4.    Data Security and Integrity:

 

A DBMS must have a mechanism to monitor user requests and be able to reject any attempts that violate the security constraints defined by the DBA. These tasks can be carried out at compile time or runtime or sometimes a combination of both.

 

5.    Data Recovery and Concurrency:

 

To implement this functionality, a DBMS or some other software component called Transaction Manager or Transaction Processing Monitor must enforce certain recovery and concurrency controls.

 

6.    Data Dictionary:

 

A DBMS must provide a data dictionary function.  A data dictionary is a database which contains ‘data about data’ called as metadata or descriptor. Instead of raw data, it contains definition of other objects in the system.

7.    Performance:

 

DBMS should perform all of the tasks mentioned above as efficiently as possible. Further, the system should process data and generate the results in an efficient way.

 

Monday, 10 August 2020

Cache coherency and consistency in OS

 

Caching:

 

Caching is an important principle of computer systems.  Information is normally kept in main memory. As it is used, it is copied into a faster storage system - the cache on a temporary basis. When we need a particular piece of information, we first check whether it is in the cache.  If it is, we use the information directly from the cache. If it is not, we use the information from the main memory and put a copy in the cache with an assumption that we will need soon in future.

 

Also the internal programmable registers like index registers provide a high speed cache for a main memory. The programmer or compiler implements the register allocation and register replacement algorithms to decide which information to keep in registers and which to keep in main memory.

 

Caches can also be implemented totally in hardware. Most systems have an instruction cache to hold the next instructions to be executed.  Without this cache the CPU would have to wait several cycles while an instruction is fetched from main memory thus making the overall processing far slow. For this reason, most systems have one or more high speed data cache in the memory hierarchy.

 

Cache management is an important design problem as cache memory has limited size.  Careful selection of the cache size and of a replacement policy can result in 80 to 99% of all accesses being in the cache, greatly increasing performance.

 

The main memory can be viewed as a fast cache for secondary storage since data in secondary storage must be copied into main memory for use and data must be in main memory before being moved to secondary storage for storing it.

 

The movement of information between levels of storage hierarchy may be either explicit or implicit depending on the hardware design and the OS software being used.  The data transfer from cache to CPU and registers is usually a hardware function. There is no intervention from the OS. Whereas the transfer of data from disk to memory is under the control of an OS.


Cache Coherency and Consistency:

 

Consider an example, suppose that an integer A is located in file B that is to be incremented by 1, and file be resides on magnetic disk. The increment operation proceeds by first issuing an IO operation to copy the disk block on which A resides to main memory. This operation is followed by copying A to the cache and to an internal register. Thus the copy of A appears in several places:  on the magnetic disk, in main memory, in the cache and in an internal register.


Migration of integer A

Fig:  Migration of integer A from disk to register

Once the increment takes place in the internal register, the value of A differs in the various storage systems. The value of A becomes the same only after the new value of A is written from the internal register back to the magnetic disk.

 

In a computing environment where only one process execute at a time, this arrangement poses no difficulties, since an access to the integer A will always be to the copy at the highest level of the hierarchy.  However, in a multitasking environment where the CPU is switched back and forth among various processes extreme care must be taken to ensure that if several processes wish to access A, then each of these processes will obtain the most recently updated value of A.

 

The situation becomes more complicated in a multiprocessor environment where in addition to maintaining internal registers each of the CPU also contains a local cache. In such an environment a copy of A may exist simultaneously in several caches. Since the various CPUs can all execute concurrently we must make sure that an update to the value of A in one cache is immediately reflected in all other caches where A resides.  This situation is called cache coherency and it is usually a hardware problem.

 

In a distributed environment the situation becomes even more complex.  In such an environment several copies of the same file can be kept on different computers that are distributed in space. Since the various replicas may be accessed and updated concurrently we must ensure that when a replica is updated in one place all other replicas are brought up to date as soon as possible.


Thursday, 6 August 2020

What are instance and schema in DBMS?

 

Instances and Schema in Database Management Systems (DBMS):

The database changes over time as data or information is inserted, updated and deleted. An instance of the database can be defined as the collection of information stored in the database at a particular moment.

OR

The state of database at any particular moment of time i.e. the collection of data, information along with various object definitions is called the instance of the database.

 

Whereas, the overall design of the database is called the database schema. In database terminology, the structure is a schema and instance of a schema is a database. We can better describe the concept of schemas and instances by considering an analogy to a program written in a programming language. 

 

A database schema corresponds to the variable declarations along with associated type definitions in a program. Each variable has a particular value at a given instance of time. These values of the variables in a program at a given time correspond to an instance of a database schema.

 

Database systems have several schemas that are divided according to the levels of abstraction. The physical schema describes the database design at the physical level while the logical schema describes the database design at the logical level.

 

A database may also have several schemas at the view level. They are generally called as subschemas that describe different views of the database. The logical schema is the most important in terms of its effect on application programs as programmers construct applications by using the logical schema.

 

The physical schema is hidden beneath the logical schema and can usually be changed easily without affecting application programs. Application programs are said to exhibit Physical Data Independence if they do not depend on the physical schema and so they need not be rewritten if the physical schema changes.

 

 A database schema defines its entities and the relationship among them. The database schema is a descriptive detail of the database which can be depicted by means of schema diagrams.


Schema and Instance in database

 Differences between schema and instance:

SN

Schema

Instance

1

The database schema describes the logical view of an entire database.

A database instance is a state of operational database with data at any given time.

2

It tells about how the data is organized and how they are related with each other.

It is a snapshot of database. It tends to change with time.

3

A schema is called as intension.

An instance is called as extension.

4

A database schema does not contain any data or information.

An instance contains information which changes when updates are done.

5

It display only names of record types (entities) and names of data items (attributes) and does not show the relationships among the various files.

An instance will be a set of values of attributes at a given time.

6

The schema will be same but, values in it will change.

An instance of a database changes from time to time.

7

Example:  Student Schema

RN

Name

Address

Class

Phone

Email

 

 

 

 

 

 

 

 

 

 

 

 

Example: Student Instance

RN

Name

Address

Class

Phone

Email

101

Ajay

Arvi Naka, Wardha

XII

123456

ajay@test.com


What are the characteristics of Modern Operating Systems (OS)?

Characteristics of Modern Operating Systems:

 

The features like huge lines of code or a large number of unnecessary features are not only the good characteristics of operating system. In order to say that a particular OS is modern, we have to consider it’s designing concepts before in order to say that it is a modern operating system.

 

Modern operating systems have the following important characteristics:

 

1.    Object Oriented Design:

This is the current and latest trend in designing of operating systems in which the OS creates the object for each facility. Each object is defined using corresponding attributes and has a set of operations.

 

2.     Multithreading:

An application or a program is divided into a number of smaller tasks. These tasks are executed by the processor concurrently. These smaller tasks are called Threads.  A thread is a lightweight process or a dispatchable unit of work. A thread has some of the characteristics of the process but there are differences -Threads share the same memory space, processes don’t share the memory space.

 

Multithreading is the ability of a processor by which number of independent threads in an application are executed by the processor at a time. A notable example of multithreading is when we type a document in MS Word. The typed text is formatted, it is spell checked automatically to detect errors and the document can be saved automatically. All these individual tasks are called threads.

 

 

3.    Symmetric Multiprocessing:

 A computer having more than one processor is called a multiprocessor. In a multi processor computer, processes can share the memory and IO facilities. Further, these processes share the same job for execution. Such a system is called symmetric multiprocessor system.

 

An OS designed for symmetric processing is called symmetric multiprocessing operating system. The main function of OS is to schedule the jobs over the multiple processors. Symmetric multiprocessing has the following advantages over uni-processor architecture:

 

Improved Throughput:  throughput means number of jobs executed by the processor in a given time. As multiple processes can be executed, we get a better throughput.

 

Improved Reliability: even if one processor fails due to hardware problems, even then the jobs can be executed with the help of other processors. The performance of the system is affected (lowered) but the system withstands the complete failure.

 

Faster Execution:  from the user point of view, jobs are executed very fast.

 

 

4.    Distributed Operating System: 

 

Distributed operating system is an OS that runs on a network of computers. The OS, memory, files are shared by the number of users in the network from the server. For example 10 nodes are connected by server through LAN.  The OS, data files, RAM, processor slots are shared by 10 users from server. The user thinks that he is running on a single large system with one operating system. The users of a distributed system do not need to know where on the network their files reside.

 

 

5.    Microkernel architecture:

It’s a minimal kernel of an OS that performs only the essential functions.  The system processes perform all other OS functions. Note that, here the system processes means servers, and systems that contains the server are called client server model systems.