Tuesday 25 August 2020

What is an attribute? What are the various types of attributes?

 

Attribute and its various types:

 

 Attribute:

 

An entity is represented by a set of attributes. Attributes are descriptive properties possessed by each member of an entity set. Each entity has a value for each of its attributes. For ex: a particular customer entity may have the value 12345 for Customer-ID.

 

For each attribute there is a set of permitted values called the domain, or value set of that attribute. The domain of attribute customer name might be the set of all text strings of a certain length.

 

Types of attributes:

 

1.    Simple and Composite Attribute:

 

If attributes cannot be further divided into sub-parts then they are known as simple attribute. Composite attributes on the other hand can be divided into sub parts. For ex: an attribute name would be structured as a composite attribute consisting of First-name, Middle-name, and Last-name.


Composite attribute

Fig: Example of composite attributes


2.    Single and Multi-valued attributes:

 

The Loan-number attribute for a specific loan entity refers to only one loan number. Such attribute is called as single valued attribute. There may be instances where an attribute has a set of values for a specific entity. Consider an employee entity set with the attribute phone number. An employee may have zero, one or several phone numbers and different employees may have different numbers of phones. This type of attribute is said to be multi-valued attribute.

 

3.    Derived attributes:

 

The value for this type of attribute can be derived from the values of other related attributes or entities. As an example, suppose that the Customer entity set has an attribute age which indicates the customer’s age. If the customer entity set also has an attribute date-of-birth, we can calculate age from date of birth and the current date. So, age is a derived attribute. In this example, date-of-birth may be referred as a base attribute.


Composite, multi-valued and derived attributes

Fig: Example of composite, multi-valued and derived attributes


4.     Null attribute:

 

An attribute takes a null value when an entity does not have a value for it. Null value may indicate not applicable, i.e. the value does not exist for the entity. For ex: one may have no middle name. Null can also designate that an attribute value is unknown. An unknown value may be either missing or not known.


Differences between Weak entity sets and Strong entity sets

Weak entity sets and Strong entity sets


Weak entity sets:

 

If an entity set do not have sufficient attributes to form a primary key, then such an entity set is termed as a weak entity set. For ex: consider the entity set payment which has the three attributes: payment - number, payment - date and payment -amount.

 

Payment numbers are typically sequential numbers, starting from 1, generated separately for each loan. Although, each payment entity is distinct, payments for different loans may share the same payment - number. Thus, this entity set does not have a primary key; as such, it is a weak entity set.

 

In order to be meaningful, weak entity set must be associated with another entity set, called as identifying or owner entity set. This means that a weak entity set is said to be existence dependent on the identifying entity set. An identifying entity set is said to own the weak entity set that it identifies.

 

The relationship associating the weak entity set with the identifying entity set is called the identifying relationship. Identifying relationship is many to one (M: 1) from the weak entity set to the identifying entity set, and the participation of the weak entity set in the relationship is total.

 

In our example, the identifying entity set for a payment is loan, and a relationship loan-payment that associates payment entities with their corresponding loan entities is the identifying relationship.

 

The discriminator of a weak entity set is a set of attributes that allows this distinction to be made. For ex: the discriminator of the weak entity set payment is the attribute payment- number, for each loan, if payment number uniquely identifies one single payment for that loan. A discriminator of a weak entity set is also called the partial key of the entity set.

 

The primary key of a weak entity set is formed by the primary key of the identifying entity set, plus the weak entity set’s discriminator. In case of the entity set Payment, its primary key (PK) is {loan- number, payment-number}, where Loan - number is the primary key of the identifying entity set, namely loan, and payment - number distinguishes payment entities within the same loan. The identifying relationship set should have no descriptive attributes.

A weak entity set can participate in relationships other than the identifying relationship. For instance, the payment entity could participate in a relationship with the Account entity set, identifying the account from which the payment was made. A weak entity set may participate as owner in an identifying relationship with another weak entity set. It is also possible to have a weak entity set with more than one identifying entity set.

 

In ER diagrams, a doubly out lined box indicates a weak entity set, and doubly outlined diamond indicates the corresponding identifying relationship.


E-R diagram for weak entity set

Fig: E-R diagram showing weak entity set

In above fig., the weak entity set payment depends on the strong entity set loan via the relationship set loan- payment. The above fig. also depicts the use of double lines to indicate total participation.

 

The participation of the weak entity set payment in the relationship loan – payment is total, meaning that every payment must be related via loan - payment to some loan. An arrow (🠈) from loan – payment to loan indicates that each payment is for a single loan. The discriminator of a weak entity set is also underlined but with a dashed rather than a solid line.


Strong entity set:

 

Entity types that consist of key attributes are called strong entity sets. The strong entity set consists of parent entity type or dominant entity type. Strong entity type set can always be represented as complex (composite, multivalued) attributes.


Strong entity set

Here, loan is an entity having a primary key called Loan_no. Hence, loan is a strong entity.


Differences between strong entity set and weak entity set:

Strong entity set

Weak entity set

An entity set having a primary key is termed as strong entity set.

An entity set is termed as weak entity set if its existence depends on other entities i.e. strong entities.

It has sufficient attributes to form a primary key.

A weak entity set does not have sufficient attributes to form a primary key.

Strong entity set is indicated in ER diagrams by a single outlined rectangle.

A weak entity set is indicated in ER diagrams by a doubly outlined rectangle.

The primary key of a strong entity set is formed by primary key of strong entity set.

The primary key of weak entity set is formed by primary key of strong entity set, plus its discriminator.

Strong entity set is not existence dependent on the identifying entity set.

 Weak entity set is said to be existence dependent on the identifying entity set.

 

Basic Concepts of Entity-Relationship (E-R) Model

Basic Concepts of Entity – Relationship (E – R) Model:

1.    Entity:

 

An entity can be defined as a ‘thing’ or ‘object’ in the real world that can be distinguished from all other objects. For ex: each person in an organization or enterprise is an entity.

 

An entity has a set of properties. Furthermore, the values for some set of properties may uniquely identify an entity. For ex: a person may have a Person-ID property, whose value uniquely identifies that person. So, the value 123-456-789 for a Person- ID would uniquely identify one particular person in an organization.

 

An entity may be concrete such as a person or a book or it may be abstract such as a loan or a holiday or a concept.

 

 

2.     Entity set:

 

An entity set can be defined as a set of entities of the same type that share (have) the same properties or attributes. For ex: the set of all persons who are customers at a given bank can be defined as the entity set Customer.

 

The individual entities that constitute a set are said to be the extension of the entity set. As such, all the individual bank customers are considered as an extension of the entity set Customer.

 

Entity sets do not need to be disjoint. For ex: it is possible to define an entity set of all employees of a bank (Employee) and the entity set of all customers of the bank (Customer). A person entity may be an employee entity, a customer entity, both or neither.

 

 

3.    Relationship:

 

A relationship can be defined as an association among several entities. For ex: we can define a relationship that associates customer Vinod with loan L-10. This relationship specifies that Vinod is a customer with a loan number L-10.

 

 

4.     Relationship set:

 

A relationship set is a set of relationships of the same type. Formally, it is a mathematical relation on n>=2 (possibly non distinct entity sets).



What are the various Data Models in DBMS?

 Data Models in DBMS:

 

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

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

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.



Monday 24 August 2020

Operations on Process - Creation, Termination and Concurrent Processes in OS:

 

Operations on Process:

In most of the operating systems, a processor supports at least two modes of execution:

1.    User mode – it is a less privileged mode. All user programs run in this mode.

2.    Kernel mode – it is a more privileged mode. All the OS related tasks are executed in this mode. A kernel mode is also called as a system mode or control mode.

 

The mode of execution is indicated by a bit in the program status word (PSW).

 

1.    Process Creation:

 

An OS creates a new process with the specified or default attributes and an identifier.  A process may create several new sub-processes.

 

Syntax for new process creation: CREATE (ProcessID, attributes), where CREATE is a system call. They have two types - Parent process and Child process.

 

A parent process is a creating process whereas; a child process is created by the parent process. A child process may create another sub processes for which it acts as a parent.  As such, it forms a tree of processes. When OS issues a CREATE system call, it obtains a new PCB from the pool of free memory, fills the fields with parameters (provided and default) and insert the PCB into the ready list. Thus, this makes the specified process eligible for execution.


Commonly required parameters when a process is created include:

·         priority of a process

·         privilege level

·         memory resources

·         access permissions

·         memory protection information, etc.

 

Moreover, a process will require certain resources such as CPU time, memory, files and IO devices to complete its operation.  When a process creates a sub-process, it may obtain its resources either directly from an OS or it uses the resources of parent process.

 

When a parent process creates a new child process, they can execute in one of the following way:

1.    Parent continues to execute concurrently with its child.

2.    Parent waits until some or all of its child processes have terminated.

 

Similarly, with regards to an address space, the two possibilities that can occur:

1.    Child process is a duplicate of the parent process.

2.    Child process has a program loaded into it.

 

Following are the possible reasons for process creation:

1.    New batch job: a batch job is provided to OS.

2.    Interactive logon: user at a terminal logs on to the system.

3.    Created by OS on behalf of a user program.

 

2.    Process Termination :

 

A DELETE system call is used for terminating a process.  A process can terminate itself or it may be terminated by another process using an appropriate system call. When a process is terminated, OS reclaim all the resources that were allocated to it and close all files opened by that process. Further, OS removes PCB and returns it to the free pool. The delete service is a normally invoked as a part of orderly program termination.

 

Possible reasons for process termination are as follows:

1.    A process has completed its normal operation.

2.    When parent terminates, it terminates the child process.

3.    A process has run longer than the specified total time length.

4.    Process requires more memory than the system can provide.

5.    Process tries to access un-allowed memory location.

6.    An attempt to execute invalid instruction.

7.    Privileged instruction- process tries to use an instruction reserved for OS only.

1.    Protection error - process attempts to use a resource that it is not allowed to use.

2.    If a deadlock exists in the system, an OS may terminate a process.

3.    Data misuse - a piece of data is of wrong type or is not initialised.

 

 

Concurrent Processes:

 

The two processes are said to be serial processes, if the execution of one must complete before the execution of another process starts. The two processes are called concurrent, if they are not serial and their execution can overlap in time. 

 

Consider the following figure:


Serial process execution


Concurrent process execution


In Fig (a), process P1 starts its execution at time T0; process P2 starts its execution only after process P1 has finished its execution.  Similarly, process P3 starts its execution only after process P2 has finished its execution.  Thus, these processes are said to be serial processes.

 

Now, consider Fig (b), where the execution time of processes P1, P2 and P3 are overlapped. Therefore, they are called as concurrent processes.


Suspended Processes, Process Control Block (PCB) and Spawning of Processes in OS:

 

Suspended Processes:

·         They are not immediately available for execution.

·         A process may or may not be waiting for an event.

·         To prevent its execution, a process can be suspended by an OS, parent process, process itself and an agent.

·         A process may not be removed from the suspended state until the agent orders the removal.

·         A technique called swapping is used to move all processes from main memory to disk. When all the processes in the main memory are in blocked state, the OS can suspend one process by putting it in suspended state and transferring it to disk.



 Possible reasons for process suspension are:

1.    Swapping: OS needs to release required main memory to bring in a process that is ready to execute.

2.    Timing: process may go to suspended state while waiting for the next time interval.

3.    Interactive user request: process may be suspended for debugging purposes by user.

4.    Parent process request: to modify the suspended process or to co-ordinate the activity of various descendants of the process.


Process Control Block (PCB):

Every process contains a special data structure called as the process control block. The PCB is used by an operating system for grouping of all information about that particular process. The following figure shows the structure of a PCB:


Process Control Block

1.    Pointer: it points to another process control block. A pointer is used for maintaining the scheduling list.

2.    Process state: process state may be new, ready, running, waiting and so on.

3.    Program counter (PC): it indicates the address of the next instruction to be executed for the current process.

4.    Event information: for a process in the blocked state, this field contains information concerning the event for which the process is waiting.

5.    CPU register: it includes general purpose register, stack pointer (SP), index registers and accumulators (ACC), etc. The total number of registers and type of registers depends upon the computer architecture of a system.

6.    Memory management information: this information may include the values of the base and limit register. It is useful for de-allocating the memory when the process terminates.

7.    Accounting information: this information includes the amount of CPU and real time used, time limits, job or process numbers, account numbers, etc.


A PCB also includes information about CPU scheduling, IO resource management, file management information, process priority, etc. It acts as a repository of information, and this information can vary from a process to process.

 

When a process is created, hardware registers and flags values are set that are provided by the loader or linker. Whenever that process is suspended, the contents of the processor register are usually saved on the stack and the pointer to the related stack frame is stored in the PCB. So, in this way the hardware state can be restored when the process is scheduled to run again.


Spawning:

A process that creates a new process is named as the parent process, and the created process is called the child process. This method of creating a new process is said to be spawning a process. Furthermore, a child process could itself spawn a new process. This results in formation of tree of processes which provides us hierarchical process structure.


Hierarchical process structure