Tuesday, 15 September 2020

Generalization - Extended E-R model feature

 Generalization:

 

There are two ways of design process: top-down and bottom-up. A refinement from an initial entity set into successive levels of entity subgroupings represents a top down design process in which distinctions are made explicit. In bottom-up design, multiple entity sets are synthesized into a higher-level entity set on the basis of common features.

 

The DB designer may have first identified a customer entity set with attributes name, street, city, and customer-id, and then an employee entity set with attributes name, street, city, employee-id, and salary. There are similarities between the customer entity set and the employee entity set as they have several attributes in common.

 

This similarity or commonness can be expressed by generalization. It is a containment relationship that exists between a higher-level entity set and one or more lower-level entity sets.


In the above example, person is the higher-level entity set and customer and employee are lower-level entity sets. These higher and lower level entity sets can be also called as superclass and subclass respectively. The person entity set is the superclass of the customer and employee subclasses. A generalization is a simple inversion of specialization.


Generalization representation


Specialization stems from a single entity set. It emphasizes differences among entities within the set by creating distinct lower-level entity sets. These lower-level entity sets may have attributes, or may participate in relationships, that do not apply to all the entities in the higher-level entity set. The reason a designer applies specialization is to represent such distinctive features.

 

Generalization proceeds from the recognition that a number of entity sets share some common features. On the basis of their commonalities, generalization synthesizes these entity sets into a single, higher-level entity set. Generalization is used to emphasize the similarities among lower-level entity sets and to hide the differences.



Specialization - Extended E-R model feature

 

Extended E-R Features:

 

The basic E-R concepts can model most database features. But, some aspects of a database may be better expressed by certain extensions to the basic E-R model.

 

1.   Specialization:

 

An entity set may include subgroupings of entities that are distinct in some way from other entities in the set. For ex: a subset of entities within an entity set may have attributes that are not shared by all the entities in the entity set. The E-R model provides a means for representing these distinctive entity groupings.

 

Consider an entity set person, with attributes name, street, and city. A person may be further classified as one of the following:

• customer

• employee

 

Each of these person types is described by a set of attributes that includes all the attributes of entity set person plus possibly additional attributes. For ex: customer entities may be described further by the attribute customer-id, whereas employee entities may be described further by the attributes employee-id and salary.

 

The process of designating subgroupings within an entity set is called specialization. The specialization of a person allows us to distinguish among persons according to whether they are employees or customers.

 

Consider another ex: suppose the bank wishes to divide accounts into two categories viz. checking account and savings account. Savings accounts need a minimum balance, but the bank may set interest rates differently for different customers, offering better rates to favored customers. Checking accounts have a fixed interest rate, but offer an overdraft facility; the overdraft amount on a checking account must be recorded.

 

The bank could then create two specializations of account, namely savings-account and checking-account. The account entities are described by the attributes account-number and balance. The entity set savings-account would have all the attributes of account and an additional attribute interest-rate. The entity set checking-account would have all the attributes of the account, and an additional attribute overdraft amount.

 

The specialization can be applied repeatedly to refine a design scheme. For ex: bank employees may be further classified as one of the following:

• officer

• teller

• secretary

 

Each of these employee types is described by a set of attributes that includes all the attributes of entity set employee plus additional attributes. For ex: officer entities may be described further by the attribute office-number, teller entities by the attributes station-number and hours-per-week, and secretary entities by the attribute hours-per-week. Further, secretary entities may participate in a relationship secretary-for, which identifies which employees are assisted by a secretary.

 

An entity set may be specialized by more than one distinguishing feature. In the above example, the distinguishing feature among employee entities is the job the employee performs. Another form of specialization that could exist can be based on whether the person is a temporary or a permanent employee. This results in the entity sets temporary-employee and permanent-employee.

 

When more than one specialization is formed on an entity set, a particular entity may belong to multiple specializations. For ex: a given employee may be a temporary employee who is a secretary.

 

In the E-R diagram, specialization is depicted by a triangle component labeled ISA. The label ISA stands for “is a” and represents, for ex: that a customer “is a” person. The ISA relationship may also be referred to as a superclass-subclass relationship. Higher- and lower-level entity sets are depicted as regular entity a set—that is, as rectangles containing the name of the entity set.


Specialization representation




Monday, 14 September 2020

Microkernel architecture in OS

 

Microkernels:

 

A microkernel is a software program loaded in main memory to perform some of the functions of the operating system so that the size of OS can be reduced. Microkernel provides process scheduling, memory management and communication services. Initially, microkernel approach was used in MACH Operating System. Later on, as its popularity increased, this approach was used in Windows 2000.

 

 Microkernel architecture:

Micro-kernel architecture

Fig: Microkernel architecture

 

In the microkernel architecture, essential and main operating system functions should be executed in the kernel mode. Remaining all i.e. less essential services and applications are built on microkernel and execute in user mode. In ordinary operating systems like layered operating systems, all the essential functions are executed in kernel mode only.

 

Microkernel is a minimal operating system that performs only the essential functions of an operating system. System processes perform all other operating system functions.

 

Benefits:

 

1.    Portability:  portability is the main feature of micro kernel. Microkernel can be suitable to any type of system. It also supports addition of new services.

 

2.    Flexibility:  microkernel architecture is flexible as existing features can be removed to produce a smaller and more efficient architecture.

 

3.    Uniform interfaces:  microkernel design imposes a uniform interface on requests made by a process.

 

4.    Extensibility:  the microkernel architecture can incorporate the new services as well as new hardware devices.

 

5.    Reliability:  as the size of software product increases, the reliability will decrease. Here, the microkernel reduces the size of operating system. So reliability will increase.

 

6.    Object Oriented: it supports object oriented OS.

 

Differences between Monolithic and Microkernel:

Monolithic Kernel

Microkernel

Kernel size is large.

Kernel size is small.

OS is complex to design.

OS is easy to design, implement and install.

Request may be serviced faster.

Request may be serviced slower compared to monolithic kernel.

All OS services are included in kernel.

Kernel provides only IPC and low level device management services.

No message passing and context switching is required while kernel is performing the job.

It requires message passing and context switching facilities.



Wednesday, 2 September 2020

User level and Kernel level threads in OS

  Process vs. Thread:

Parameter

Process

Thread

Sharing of memory and address space

It can't share same memory area i.e. address space.

Threads can share memory and files.

Time for creation

It takes more time to create a process.

It takes less time to create a thread.

Time for termination

Requires more time to complete the execution and termination of process

 Less time for termination.

Execution speed

Execution is very slow.

Execution is a very fast.

Time for switching

Requires more time to switch between two processes.

Requires less time to switch between two threads.

Communication

Implementing communication between processes is bit more difficult.

Communication between two threads is very easy to implement because threads share the same memory.

System calls

Required to communicate with each other.

System calls are not required.

Coupling

Process is loosely coupled.

Threads are tightly coupled.

Resource requirement

It requires more resources to execute.

Requires fewer resources, hence, called as lightweight process.

Parallelism

Processes are not suitable for parallel activities.

Suitable for parallel activities.


Thread Functionalities:

 

 Thread synchronization:

 

All threads within a process share the memory and files. If one thread is trying to modify one record in a file, it will affect with another threads. Hence, there is a need of mechanism for synchronizing the activities of thread.

  

User level and Kernel level threads:

 

 There are two main ways to implement threads:

1.    In user space and;

2.    In the kernel.

  

1.   User Level Threads:

 

These types of threads are loaded entirely in a user space; the kernel knows nothing about them. When Threads are managed in user’s space, each process needs its own private thread table. A thread table consists of the information of program counter, stack pointer, registers, state, etc.  The thread table is managed by runtime system. When a thread is moved to ready state or blocked state, the information needed to restart it is stored in the thread table.


User level thread


Advantages:

 

·         They allow each process to have its own scheduling algorithm.

·         Entire process is loaded in user space, so the process does not switch to the kernel mode to do thread management. This saves the overhead of two mode switches.

·         They can run on any operating system.

 

 

 Disadvantages:

·         When a user level thread executes a system call, not only the particular thread gets blocked but, all of the threads within the process are blocked.

·         In user level threads, only a single thread within a process can execute at a time. So, multiprocessing cannot be implemented.


2.   Kernel Level Threads:

 

In kernel level threads, the kernel does total work of thread movement. There is no thread table in each process.  The kernel has a thread table that keeps track of all the threads in system. When a thread wants to create a new thread or destroy any existing thread, it makes a kernel call, which takes the action.

 

The kernel’s thread table holds each thread registers, state and their information. The information is saved as with user level threads, but it is now in the kernel instead of the user space.


Kernel level thread

Advantages:

 

·         The kernel can simultaneously schedule a multiple threads from the same process on multiple processors. This means it supports multiprocessing whereas, user level threads can't support this.

·         If a thread in a process is blocked; the kernel can schedule another thread of the same process.

·         The kernel routine themselves can be multithreaded.

·         Scheduling by kernel is done on a thread bus.

 

 Disadvantages:

 

·         More cost for creating and destroying threads in the kernel.

·         Transfer of control from one thread to another within the same process requires a mode switch to the kernel.

 

 3.   Combined approaches:

 

If we combine both approaches then we get the advantages of both. Some operating systems provide this type of facility. In combined system, thread creation is done completely in user space. Best example for this approach is Sun Solaris.


Thread Life Cycle and Multi-threading concepts in OS

 

Concepts of Threads:

 

A process is divided into number of lightweight process.  Each light weight process is said to be a thread.  The thread has a program counter that keeps the track of which instruction to execute next, it has a registers, which holds its current working variables.  It has a stack which contains the execution history.

 

Number of threads can share an address space, open files and other resources. Same as a number of processes can share their physical memory, disks, printers and other resources. Threads operates in many respects in the same manner as process as they have some of the properties of process.

 

Threads can be in one of several states: Ready, Blocked, Running Terminated.  Like process, threads share the CPU, and only one thread at a time is active or running. Threads can create a child threads. Unlike process, threads are not independent of one another. As all threads can access every address in the stack; a thread can read or write over any other thread stacks.

 

The programmer specifies that application contain ‘Threads of execution’. It describes each thread designating portion of program that may be executed concurrently with other threads. This capability is called multi-threading.

 

Life cycle of Thread:

 

A thread is said to be in one of the following several thread states:

 

·         Born state:  a thread has just been created.

 

·         Ready state:  the thread is waiting for CPU.

 

·         Running state:  the system assigns the processor to the thread.

 

·         Blocked state:  the thread is waiting for an event to occur or waiting for an IO device.

 

·         Sleep state: sleeping thread becomes ready after the designated sleep time expires.

 

·         Dead or Terminated state: the thread has finished its execution.

 

Thread Life Cycle


Multi-threading:


Single-threaded and multi-threaded process
Fig: Single-threaded and multi-threaded process


A process is divided into a number of smaller tasks; each task is called a thread. Number of threads within a process execute at a time. This is called as multi-threading.  Supporting of multithreading is the additional capability of an operating system. Based on the functionality, threads are divided into four categories. These are:

 

1.    One Process One Thread:

It is a traditional approach in which the process maintains only one thread. Hence, it is called single thread approach. For ex: MS DOS operating system supports this type of approach.

 

2.    One Process, Multiple Threads:

In this approach, a process is divided into a number of threads. Best example for this is a Java Runtime Environment (JRE).

 

3.    Multiple Process, One Thread Per Process:

An OS supports multiple user processes but only support one thread per process. UNIX is the best example of this.

 

4.    Multiple Processes, Multiple Threads Per Process:

In this approach, each process is divided into a number of threads. For ex: Windows 2000, Sun Solaris and Linux.

 

Advantages of a thread:

 

1.    A thread takes less time to terminate than a process.

 

2.    It takes less time to switch between two threads within the same process.

 

3.    It takes less time to create a new thread within the process.

 

4.    Efficient communication between threads is possible.

Tuesday, 1 September 2020

Entity - Relationship (E - R) Diagram in DBMS

 Entity - Relationship (E - R) Diagram:

The Entity Relationship (E-R) data model is based on a perception of a real world that consists of a collection of basic objects called entities and of relationships among these objects. An entity is a thing or object in the real world that is distinguishable from other objects. For example each person is an entity, and bank accounts can be considered as entities.

 

Entities are described in a database by a set of attributes. For example the attributes account number and balance may describe one particular account in a bank, and therefore some attributes of the account entity set. A relationship is an association among several entities. For example a deposit a relationship associates a customer with each account that he or she has.

 

The set of all entities of the same type and the set of all relationships of the same type are termed as entity set and relationship set respectively. The overall logical structure (schema) of a database can be expressed graphically by an ER diagram which is the built up from the following components:

 

·         Rectangles- it represent entity sets

 

·         Ellipses: it represents attributes

 

·         Diamonds: it represents relationship sets

 

·         Lines: it link attributes to entity sets and entity sets to relationship sets

 

·         Double ellipses: it represents multivalued attributes

 

·         Dashed ellipse:  it denote derived attributes

 

·         Double lines:  it indicate total participation of an entity in a relationship set

 

·         Double rectangles: it represents weak entity set


E-R Diagram example

Fig: E-R diagram example

Consider the entity relationship diagram in the above figure which consists of two entity sets, customer and loan, related through a binary relationship set borrower. The attributes associated with customer are customer-id, customer-name, customer-street, and customer-city. The attributes associated with loan are loan- number, and amount.

 

In fig. attributes of an entity set that are members of the primary key are underlined. The relationship set borrower may be one to one, one to many, many to one, or many to many. To distinguish among these relationship types, we draw either a directed line (->) for an undirected line(---) between the relationship set and entity set in question.


Symbols used in E-R diagram:

E-R Diagram Symbols



Mapping Cardinalities or Types of Relationships in DBMS:

 

Mapping Cardinalities / Types of Relationships:

 

Mapping cardinalities or cardinality ratios express the number of entities to which another entity set can be associated via a relationship set. Mapping cardinalities are most useful in describing binary relationship sets, although they can contribute to the description of relationship sets that involve more than two entity sets.

 

For a binary relationship set R, between entity sets A and B, the mapping cardinality must be one of the following:

 

A.   One-to-One  (1:1) :

 

An entity in A is associated with at most one entity in B, and an entity in B is associated with at most one entity in A. Such a relationship is called as one to one relationship.


One to One Relationship

Fig: One to One relationship


B.    One to Many(1:M) :

 

An entity in A is associated with any number (zero or more) of entities in B. An entity in B however, can be associated with at most one entity in A. Such a relationship is called as one to much relationship.

 

One to Many Relationship

Fig: One to Many relationship


C.    Many to One(M:1):

 

An entity in A is associated with at most one entity in B. An entity in B however, can be associated with any number (zero or more) of entities in A. Such a relationship is called as many to one relationship.


Many to One Relationship

Fig: Many to One relationship


For ex: consider the borrower relationship set. If in a particular bank a loan can belong to only one customer, and a customer can have several loans, then the relationship set from customer to loan is one to many.


D.    Many to Many(M:N):

 

An entity in A is associated with any number (zero or more) of entities in B, and an entity in B is associated with any number (zero or more) of entities in A. Such a relationship is called as many to many relationship.


Many to Many Relationship

Fig: Many to Many relationship

For ex: if a loan can belong to several customers (as loans is taken jointly by several business partners), the relationship set is many to many.