Tuesday, October 13, 2020

Deadlocks in CPU

  

 What do you mean by Deadlock in CPU?

  A  deadlock is a situation  where a group  of processes is permanently  blocked as 

  a result of each process  having acquired  a  set  of  resources  needed  for its

  completion and having to wait  for  the   release of the remaining resources held 

  by  others  thus making it impossible for any of the deadlocked process to proceed.


For example assume a system with one tape drive and one plotter.Process P1 requests

the plotter and process P2 requests   the tape drive. Both requests are granted. Now

Process P1 request the tape drive(without giving the plotter) and process P2 requests

plotter(without releasing tape drive) .Neither request can be granted so both processes

enter a situation called the deadlock situation.


Hey guys before we learn more about deadlocks we must understand about the 

type of resources.

There are mainly two types of resources:

Pre emptive Resources:This process can be taken away from the process with no ill

effects.For eg Memory is an example of a pre-emptable resource   .

Non Pre-emptive Resources:This resource cannot be taken away from the process

without causing ill effect.For example CD Rom

It is to be noted that relocating resources can resolve deadlocks that involve

 pre-emptable resources  while Non pre-emptable resources are difficult to deal with.

 

Characteristics of Deadlock:

There are basically four necessary conditions that  leads to occurence of deadlock.

They are as follows:

1. Mutual Exclusion:

In this the resources used are non shareable At least one resource  must be held in a

non shareable mode.. If another process request that resource the requesting process must 

be delayed  until the resource has been released.

2:Hold and Wait Condition

In this condition a requesting process already holds resources and waits

for the requested resources. A process holding a resource allocated to it waits for

an  additional resources that is/are currently being held by other resources

3.No Preemptive condition:

Resources already allocated to a process cannot be pre-empted.Resources cannot be

removed forcibly from the processes.After completion they will be released

voluntarily by the process holding it

4. Circular Wait Condition:

The processes in the system form a circular list or chain where each process in the list

is waiting for a resource  hold by the next process in the list.

 


Tuesday, October 6, 2020

SQL Hosting

 


     What is SQL Hosting ?

      When we want our websites to store and retrieve data from the database we need

      the web server to have access to the database  system that uses SQL language. 

      The web server needs to be hosted by different ISP(Internet Service Provider)

      Let us see in detail about the SQL Hosting databases:

      1.Ms Access:  Ms access is used to store and retrieve very simple set of databases

     



     2.Oracle: It is a popular database software for  database driven websites with

                     high traffic.


 

    3.Ms SQL Server: It is also a very popular database software fordatabase driven

                                    websites with high traffic. It is very powerful and robust for 

                                    handling huge amount of data .It is of Microsoft company



    4. MySql:  It is an inexpensive alternative to Microsoft SQL and Oracle server.

                       It is also a database software used for storing and retrieving data

                      in database 


 

Database Queries in Standard Query Language

 

 
 

     1. The SQL Create Database statement:

          Syntax: Create database databasename ;

          Function: This statement is used to create a new database.

          example: Create database mydb1;

 

  2. The SQL Drop statement.

      Syntax: Drop Database databasename;

      Function: The Sql drop statement is used to delete an existing database

      example. Drop database mydb1; 


3.The SQL  Backup statement.

    Syntax: Backup Database databasename to disk ='filepath';

    Function: This statement is used to create  a full backup of existing database.

    example: Backup database mydb1 to disk ="D:\My Details";

 

4. The SQL Backup with Differential statement :

    Syntax: Backup database databasename to disk ='filepath' with differential;

    Function: This  statement is used to  keep backup of the database that have 

                      changed since the last full backup done .

     Example:  Backup database mydb1 to disk ="D:\My Details"  with differential;


5.The SQL create table statement:

    Syntax : Create table tablename{    column1 datatype,

                                                             column2 datatype,

                                                             column3 datatyoe

                                                           } 

   Function: This statement is used to create a new table in database.

  example: create table customers: { ID int(4)  Primary key,

                                                          name  Text(20)

                                                          address  Text(20)

                                                         };

6..The SQL Drop table statement:

     Syntax: Drop table tablename;

    Function: This statement is used to delete a table   from a database.

    example: Delete table customers; 

 

7. The SQL  Alter table statement:

    Syntax:Alter table tablename add columnname datatype;

    Function:  This statement is used to add and  modify data in a table

    example: Alter table customers add phonenumber int(12);



  


    


SQL Constraints


   What are SQL Constraints ?

  SQL Constraints specify  rules for data in a table.It basically limit the type  of

  data that go into the table.Let us see the type  of  constraints used in table.

   1. Primary Key:Uniquely Identifies each row in a table

   2. Foreign Key: Uniquely Identifies a row in another table

   3. Not Null: It ensures that a column should not have a Null value

   4. Unique:It ensures that all the values in the column are unique

   5. Check:It ensures that the values in the column satisfy a specific condition

   6. Default:It is used to set a default value to a column if no value is specified


 Constraints  are basically  specified during creation of  a table statement or during

 alter table statement.

 Syntax:  Create table tablename

               { column1 datatype constraint,

                  column2  datatype constraint,

                  column3 datatype constraint

             };  

 For eg:

   Create table customer

{   customerid int Primary key,

     customername text,

    customeraddress text

};

   


   

    

SQL Data Types


 

   Data types tells the computer the type of data which is going to be processed and 

   amount of memory which should be allocated  to that data.The datatype can be

   Integer, Character, Text, Date etc,

   Each column in a database should be mentioned with proper datatype to ensure

   proper insertion of data in a column.Let us see the types of data available in SQL

   Basically there are three main types of Data. String, Numeric and date and time.

   1. String Data Type :

       a. Text(size): Holds a string of maximum length of 65535 bytes

       b. Char(size): Holds letters, numbers, special characters . It is a fixed length 

                               string

       c.Varchar(size): Holds variable length string including letters, numbers,

                                   special characters

2. Numeric  Data Types:

     a.Bit(size): Holds Bit value type. The size of the parameter can hold 1 to 64

     b.INT(size): Holds medium Integer.

     c. Float(size,d) :Holds floating point number. The number of digits is specified

                                in d as parameter.

     d.Double(size,d) :A normal size floating point number. The number of digits is 

                                   specified in d as parameter.

3. Date  and Time:

     a. Date: Display in date format(yyyy-mm-dd)

     b Date and Time: Display in date and time combination(yyyy-mm-dd hh:mm:ss)

     c. time(fsp): Display in time format(hh:mm:ss)

     

Note:Datatypes have different names in different database.The size and other  details 

         may also vary.so it is always recommended to go through the documentation.

 

 

 


   



SQL Between Operator


 

  1. SQL Between Operator:

       Syntax : Select columnname(s)  from tablename  where columnname between 

                      value1 and value 2;

        Function: The Between operator is used to fetch values from particular column 

                         in a given table based on certain values.


2. SQL Not Between operator:

     Syntax: Select columnname(s)  from tablename  where columnname Not between 

                      value1 and value 2;

    Function: The Not Between operator is used to fetch values from particular column 

                         in a given table by excluding the given values.

 

3.SQL Between with IN:

Syntax: Select columnname(s)  from tableneame  Between value1 and value2 and

              columnname NOT IN(value1,value2,value3....);   

Function: SQL Between with IN is used to fetch data from particular column 

                 of a  table according to the IN Clause.

 

4. SQL Between Text values: 

    Syntax: Select Columnname(s) from tablename between "text1" and "text2";

    Function: This query is used to fetch data from the table based on two text

                    parameters.

5.SQL NOT Between Text values: 

   Syntax: Select  columnname(s)  from tablename Not Between "text1" and

                 "text2";

  Function: This query is used to fetch details from the table about particular

                    column which are not between the given text values.


6. SQL Between   Dates:

     Syntax: Select Columnname(s)  from the tablename Between 'yyyy-mm-dd' 

                   and 'yyyy-mm-dd';

                                                             OR

       Syntax: Select Columnname(s)  from the tablename Between #yyyy-mm-dd#

                   and #yyyy-mm-dd#;

      Function: This query is used to fetch details from a particular column of 

                        a table  according to the given dates.

  

 

 


   

 

 

Advanced Queries in Structured Query Language

 


   Some of the advanced Queries in SQL are as Follows: 


   1. SQL ORDER BY Clause:

      Function: This query is used to sort the fetched records in either ascending or 

                        descending order.

     Syntax: 

    Select column1.column2 from tablename Order By Columname ASC|DESC

    Let us understand with the help of an Example  :

   Table1: Customers

                 customerId               customername             customercontact            country

                        1                              Alferd                               Maria                     Germany

                        2                               Ana                                   Ana                        Mexico    

                       4                             Antonio                              Antonio                    Mexico

 Query1: SELECT customername,contactname from customers ORDER BY customername

 Output:


customername Ascending contactname
Alferd Maria
Ana Ana
Antonio Antonio  

  Query2:

  SELECT customername,contactname from customers ORDER BY customername DESC
 
 
  Output:
 
  

customername contactname
Antonio Antonio
Ana Ana
Alferd Maria   
 
 
 
 2.  SQL MIN() and MAX() Functions:
 
     Syntax: Select  MIN(columnname) from tablename where condition.
 
    Function: This query is used to fetch out the minimum value from the column name
 
    Syntax: Select  MAX(columnname) from tablename where condition.
 
    Function: This query is used to fetch out the maximum value from the column name
 
 
3.SQL COUNT()  Function: 
 
  Syntax : Select  count(columnname) from tablename where condition;
 
  Function: This function is used to return the number of values in a particular column.
 
 
4. SQL AVG()  Function: 
 
    Syntax: Select Avg(columnname)   from tablename where condition;

    Function: This function is used to return the average of the  particular column.


5. SQL SUM()  Function:
 
    Syntax: Select Sum(columnname)   from tablename where condition;

    Function: This function is used to return the sum of a particular column.



   
 
 
 
 
 
 
 
 
 
 
 
 
 

Joins in Structured Query Language


 

   1. SQL JOIN Query: 

      The Join Query is used to combine rows from two or more column based on related

      column between them. The types of Join  Query are as follows:

        A. INNER JOIN : This Join is used to fetch record that have matching values

                                        in both the table.

      B.  LEFT JOIN: This Join is used to fetch all the details from the left side of table

                                    and matching values from the right side of the table.

      C. RIGHT JOIN: This Join is used to fetch all the details from the right side of the 

                                      table and matching records from the left side of the table

      D. FULL JOIN:  This  Join is used to fetch all the records from both the left and

                                     right side of the table wherever there is matched records .

 

  Let us understand with the help of an Example  :

 Let us assume that there are two tables

Table1: Customers

                 customerId               customername             customercontact            country

                        1                              Alferd                               Maria                     Germany

                        2                               Ana                                   Ana                        Mexico    

                       4                             Antonio                              Antonio                    Mexico

Table2:Orders

                 orderId                       customerid                        orderdate

                        1                                2                                    1996-09-18       

                        2                               37                                   1996-09-19            

                       4                                77                                   1996-09-20        

 

 Syntax: INNER JOIN:   

 Select columnname(s) from tablename1 INNER JOIN tablename2 ON 

 table1.columnname=table2.columnname

Example:

select orders.orderid,customers.customername,orders.Orderdate from orders INNER JOIN customers ON orders.Cutsomerid=customers.customerID  
 
Output:
orderid  customername  Orderdate
10308    
  Ana         
1996-09-18     
 

Syntax: LEFT JOIN:

 Select  columnname(s) from table1 LEFT JOIN table2 ON 

 table1.columnname=table2.columnname;

 NOTE: If there is no match freom right side it will return NULL VALUE

               LEFT JOIN is also called as LEFT(OUTER)JOIN

 

Example:

select orders.orderid,customers.customername,orders.Orderdate  
from orders LEFT JOIN customers ON orders.Cutsomerid=customers.customerID
 
Output:
orderidcustomernameOrderdate
10308Ana 1996-09-18
10309 NULL 1996-09-19
10310 NULL 1996-09-20
 
Syntax: RIGHT JOIN
 
 Select columnname(s) from table1 RIGHT JOIN table2 ON 

  table1.columnname=table2.columnname;

  NOTE: If there is no match from right side it will return NULL VALUE

           RIGHT JOIN is also called as RIGHT(OUTER)JOIN

 

Example:
 
select orders.orderid,customers.customername,orders.Orderdate from orders RIGHT JOIN customers ON orders.Cutsomerid=customers.customerID  
 
Output:
 
orderidcustomernameOrderdate
10308 Ana 1996-09-18
NULL Alferd NULL
NULL Antonio NULL
 
 

Syntax: FULL JOIN:

 Select  columnname(s) from table1  FULL JOIN table2 ON 

 table1.columnname=table2.columnname;


Example:

SELECT customers.contactname,orders.Orderdate FROM customers FULL JOIN orders ON customers.customerID=orders.orderid;

 


 

 

              

 


Monday, October 5, 2020

Insert, Update and Delete Query in Structured Query Language


 

  1. SQL Insert Into Query 

      Syntax : Insert Into tablename (column1,column2, column3,........) 

                     Values(value1,value2,value3,............) 

      Function: The Insert query is used  to insert records in a database

      Example: Insert Into Employees(Empid, EmpName, EmpAddress, Empphone)

                       Values(1,'Ana Johnson','New York', 12345676);

 

2. SQL Update Query :

   Syntax: Update Tablename set column1 = value1, column2-=value2 ,

                 column3="value4"   where condition ;

   Function: The update query is used to modify a data in a database.

   Example: Update Employees set  EmpName="Sashank",

                     EmpAddress="Sweden" where  Empid = 3;

 

3. SQL Delete Query:

    Syntax: Delete from tablename where condition ;

    Function: This query is used to delete a record of a table.

    Example: Delete from Employee where EmpName="Ana Johnson";

     

Priority Based Scheduling or Event Driven Scheduling Algorithm

 

   What  do  you  mean  by  Priority  Based Scheduling ?

   A priority is associated  with  each process and   the scheduler always picks 

   up the highest priority process for execution from the ready queue . A major

   problem with the priority based scheduling is that there is indefinite blocking

   of  a   lost  priority  process  by a high priority  process. A solution to this

  problem is aging priority.. Aging Priority is a technique  of gradually  increasing

  the priority  of  a   process   that  wait  in  the  system  for  a  long  time.

  Eventually  the  older  process  attain  a higher  priority  and are endured of 

  completion in a finite term.


Let us understand with the help of an example:


             Process          Processing Time              Priority

                P1                     10                                     3

                P2                      1                                      1

                P3                      2                                      4

                P4                      1                                      5

                P5                      5                                      2   


Using Priority scheduling we would be scheduling the processes  according  

to  the following  Gantt Chart .

 

                          P2           P5                          P1                        P3         P4

                      0       1                   6                                       16         18         19       

 

Time            Process  Completed           Turn Around Time               Waiting Time

   0                             -----                                     ----                                   ----

   1                              P2                                    1-0=1                                 1-1=0

   6                              P5                                    6-0 =6                                6-2=4

  16                             P1                                   16-0=16                            16-10=6

  18                             P3                                   18-2=16                            18-2=16

  19                             P4                                   19-1=18                            19-1=18 


Average Turn around Time= 1+6+16+16+18/5 = 60/5 = 12

Average waiting Time = 6+0+16+18+1/5= 8.2

Throughput = 5/19 = 0.26

Processor  utilization = 30/30 * 100 = 100%


       

    

 

Shortest Remaining Time Next Scheduling Algorithm

 


  What is Shortest Remaining Time Next  Algorithm ?  

  This is the preemptive version of Shortest job first algorithm .This permits the process

  that enters the ready list to preempt the running process if the time for the new process

  is less than the remaining time fro the running process. 

  Let us understand this with the help of an example:

 Consider  the set of four process arrived as per timings described in the table

         Process                Arrival Time                           Processing Time

           P1                            0                                                  5

           P2                            1                                                  2

           P3                            2                                                  5

           P4                            3                                                  3


At time 0 only process P1 has entered the system, so its is the process that executes.

At time 1, process P2 arrives. At that time Process P1 has 4 units left to execute.

At this juncture process 2's processing time is less than P1. so P2 starts executing

at  time 1.At time 3 P3 enters the system with the processing time 5 units.Process

P2 continues executing as it has minimum processing time compared to P1 and P3 

both.At time 4 process p2 terminates and process P4 enters the system with time 3

units. Since process P4 has minimum time duration than P1 and P2 process P4 starts

executing. when process P1 terminates at time 10, process P3 enters the system.

The Gantt chart is explained below:


                         P1        P2           P4              P1             P3

                   0            1            3            6               10              15

 

Turn around Time for each of the process is given below:

                  P1 = 10 - 0 = 10

                  P2 =  3 -  1=   2

                  P3 =  15 - 2 = 13

                  P4 =  6 - 3 = 3

Average Turn around Time = 10+2+13+3/4 = 7

 

The waiting time fro each of the process  is  given  as  follows:

                             P1= 10 -5 =5

                             P2 = 2 - 2 =0

                             P3 =13 - 5 =8

                             P4 = 3 - 3 = 0


Average waiting Time =  5+0+8+0/4 = 3.25milliseconds

Four jobs executed in 15 time units, so throughput is 15/4 = 3.75 time units/job

 

 

 

             


Saturday, October 3, 2020

Round Robin Scheduling Algorithm in CPU

 

   What is Round Robin Scheduling Algorithm in CPU ?

   It is a preemptive scheduling algorithm where  the CPU is divided into  time slices

   The round robin scheduling algorithm is based on time sharing and multi user

   system environment where the primary requirement is to provide adequate time

   slices to  to every process fairly.

   How does the Round Robin Scheduling algorithm works?

   Every process is allocated a slot of time which is known as quantum.No process

   can rum more than one quantum while other processes are waiting in the ready

   queue. if a process needs more than one quantum it goes to the end of the ready

   queue to await the next allocation .The CPU scheduler picks the first process

   from the ready queue , allocate processor for the specified time quantum, After 

   that time the CPU scheduler will select the next process is the ready queue.

  Consider the following set of process with the processing time given in milliseconds

                                         Process    Processing Time

                                            P1                  24

                                            P2                  03

                                            P3                  03 


Here if we use a quantum of 4 milliseconds then process P1 gets the first 4 milliseconds.

since it requires another 20 milliseconds,it is given another time slot after giving time to

next slot. The Gantt Chart for the following process is given below:

 

       P1       P2          P3              P1            P1          P1              P1          P1  

0           4          7             10             14             18                22         26            30


 Process       Process Completed        Turn Around Time                 Waiting Time    

      P1                    24                                  30-0=30                                  30-24=6

      P2                    03                                  7-0 = 7                                     7-3=4

      P3                    03                                 10-0=10                                   10-3=7          


     Points to note :

       Average Turn around Time = 30+7+10/3 = 15.66

       Average waiting time =  6+4+7/3 = 5.66

       Throughput = 3/30 = 0.1

       Processor Utilization = 30/30 *100 = 100%    

    

         


  

 

 

Thursday, October 1, 2020

Shortest Job First Algorithm in CPU

 

    What  do  you  mean  by Shortest  Job  First  Scheduling  Algorithm ?

    This algorithm is applied in a process which has smallest  CPU processing time .

    Basically this algorithm is applied in Batch Processing system.  

     Example:

                                    Process    Processing Time

                                      P1                   06

                                      P2                   08

                                      P3                   07

                                      P4                   03

 

    Using Shortest Job First as the Shortest Job will be used first the Gantt Chart

    will be as follows:

                            P4             P1          P3              P4

                    0               3              9                 16            24 

 

      Time        Process Completed        Turn Around Time                 Waiting Time    

           0                    -                                       -                                               -

           3                   P4                                    3                                              0

           9                   P1                                    9                                              3

          16                  P3                                   16                                             9

          24                  P2                                   24                                            16

                                                          

     Point To Note

    Turn  around Time : Process Completed  - Process submitted

    Waiting Time- :  Turn around Time - Processing Time

    Average Turn around Time = (3+9+16+24)/4  =13

    Average Waiting Time = (0+3+9+16)/4 =7

    Processor Utilization = (24/24)*100 = 100%

    Throughput  = 4/24 = 0.16

First Come First Serve Scheduling Algorithm n CPU

 


 What is First Come First Served Scheduling Algorithm ?

  This is the simplest scheduling algorithm which is non preemptive.In this

  algorithm a queue of the process is scheduled and selecting the process with 

  earliest time.

 Example:

                        Process       Arrival Time        Processing Time 

                           P1                  0                             3

                           P2                  2                             3

                           P3                  3                             1

                           P4                  5                             4

                           P5                  8                             2


       If the  process  arrives  as  per  the  arrival  time the Gantt Chart will be:

                    P1       P2         P3         P4             P5

               0         3          6           7             11             13    

 

        Time        Process Completed        Turn Around Time                 Waiting Time    

           0                    -                                       -                                               -

           3                   P1                                    3                                              0

           6                   P2                                    4                                              1

           7                   P3                                    4                                              3

          11                  P4                                    6                                              2

          13                  P5                                    5                                              3

    

     Point To Note

    Turn  around Time : Process Completed  - Process submitted

    Waiting Time- :  Turn around Time - Processing Time

    Average Turn around Time = (3+4+4+6+5)/5  = 4.4

    Average Waiting Time = (0+1+2+3+4)/5 = 1.8

    Processor Utilization = (13/13)*100 = 100%

    Throughput  = 5/13 = 0.38