Sunday, 26 January 2014

Types of Operating System

Types of Operating Systems
  1.)   Batch Processing:
             The Batch Processing is same as the Serial Processing Technique. But in the Batch Processing Similar Types of jobs are Firstly Prepared and they are Stored on the Card. and that card will be Submit to the System for the Processing. The System then Perform all the Operations on the Instructions one by one. And a user can’t be Able to specify any input. And Operating System wills increments his Program Counter for Executing the Next Instruction.

The Main Problem is that the Jobs those are prepared for Execution must be the Same Type and if a job requires for any type of Input then this will not be Possible for the user. And Many Time will be wasted for Preparing the Batch. The Batch Contains the Jobs and all those jobs will be executed without the user Intervention. AndOperating System will use the LOAD and RUN Operation. This will first LOAD the Job from the Card and after that he will execute the instructions. By using the RUN Command.

The Speed of the Processing the Job will be Depend on the Jobs and the Results those are produced by the System in difference of Time which is used for giving or submit the Job and the Time which is used for Displaying the Results on the Screen.

2)     Multi-Programming:
  In Multi programming we can Execute Multiple Programs on the System at a Time and in the Multi-programming the CPU will never get idle, because with the help of Multi-Programming we can Execute Many Programs on the System and When we are Working with the Program then we can also Submit the Second or Another Program for Running and the CPU will then Execute the Second Program after the completion of the First Program. And in this we can also specify our Input means a user can also interact with the System.

The Multi-programming Operating Systems never use any cards because the Process is entered on the Spot by the user. But the Operating System also uses the Process of Allocation and De-allocation of the Memory Means he will provide the Memory Space to all the Running and all the Waiting Processes. There must be the Proper Management of all the Running Jobs.
3)   Timesharing (multitasking) is logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing
o   Response time should be < 1 second
o   Each user has at least one program executing in memory [process
o   If several jobs ready to run at the same time [ CPU scheduling
o   If processes don’t fit in memory, swapping moves them in and out to run
o   Virtual memory allows execution of processes not completely in memory
4) Real Time System: There is also an Operating System which is known as Real Time Processing System. In this Response Time is already fixed. Means time to Display the Results after Possessing has fixed by the Processor or CPU. Real Time System is used at those Places in which we Requires higher and Timely Response. These Types of Systems are used in Reservation. So when we specify the Request, the CPU will perform at that Time. There are two Types of Real Time System

1)   Hard Real Time System: In the Hard Real Time System, Time is fixed and we can’t Change any Moments of the Time of Processing. Means CPU will Process the data as we Enters the Data.

2)   Soft Real Time System: In the Soft Real Time System, some Moments can be Change. Means after giving the Command to the CPU, CPU Performs the Operation after a Microsecond.

5) Distributed Operating System. - Distributed Means Data is Stored and Processed on Multiple Locations. When a Data is stored on to the Multiple Computers, those are placed in Different Locations. Distributed means In the Network, Network Collections of Computers are connected with Each other.

Then if we want to Take Some Data From other Computer, Then we uses the Distributed Processing System. And we can also Insert and Remove the Data from out Location to another Location. In this Data is shared between many users. And we can also Access all the Input and Output Devices are also accessed by Multiple Users.

6) Multiprocessing: Generally a Computer has a Single Processor means a Computer have a just one CPU for Processing the instructions. But if we are Running multiple jobs, then this will decrease the Speed of CPU. For Increasing the Speed of Processing then we uses the Multiprocessing, in the Multi Processing there are two or More CPU in a Single Operating System if one CPU will fail, then other CPU is used for providing backup to the first CPU. With the help of Multi-processing, we can Execute Many Jobs at a Time. All the Operations are divided into the Number of CPU’s. if first CPU Completed his Work before the Second CPU, then the Work of Second CPU will be divided into the First and Second

Friday, 24 January 2014

C - Type casting
·         Type casting is a way to convert a variable from one data type to another data type.
·         For example, if we want to store a long value into a simple integer then we can type cast long to int.
·         We can convert values from one type to another explicitly using the cast operator as follows:
(type_name) expression
Consider the following example where the cast operator causes the division of one integer variable by another to be performed as a floating-point operation:
#include <stdio.h>

main()
{
   int sum = 17, count = 5;
   double mean;

   mean = (double) sum / count;
   printf("Value of mean : %f\n", mean );

}
When the above code is compiled and executed, it produces the following result:
Value of mean : 3.400000
It should be noted here that the cast operator has precedence over division, so the value of sum is first converted to type double and finally it gets divided by count yielding a double value.
Type conversions can be implicit which is performed by the compiler automatically, or it can be specified explicitly through the use of the cast operator. It is considered good programming practice to use the cast operator whenever type conversions are necessary.
Integer Promotion
Integer promotion is the process by which values of integer type "smaller" than int or unsigned int are converted either to int or unsigned int. Consider an example of adding a character in an int:
#include <stdio.h>

main()
{
   int  i = 17;
   char c = 'c'; /* ascii value is 99 */
   int sum;

   sum = i + c;
   printf("Value of sum : %d\n", sum );

}
When the above code is compiled and executed, it produces the following result:
Value of sum : 116
Here, value of sum is coming as 116 because compiler is doing integer promotion and converting the value of 'c' to ascii before performing actual addition operation.
Usual Arithmetic Conversion
The usual arithmetic conversions are implicitly performed to cast their values in a common type. Compiler first performs integer promotion, if operands still have different types then they are converted to the type that appears highest in the following hierarchy:
long bouble

double


float

unsigned long long

long long


unsigned long

long

unsigned int

int


The usual arithmetic conversions are not performed for the assignment operators, nor for the logical operators && and ||. Let us take following example to understand the concept:
#include <stdio.h>

main()
{
   int  i = 17;
   char c = 'c'; /* ascii value is 99 */
   float sum;

   sum = i + c;
   printf("Value of sum : %f\n", sum );

}
When the above code is compiled and executed, it produces the following result:
Value of sum : 116.000000
Here, it is simple to understand that first c gets converted to integer but because final value is double, so usual arithmetic conversion applies and compiler convert i and c into float and add them yielding a float result.


C - Pointers

Pointers:
·         Pointers are variables that contain memory addresses and are used to access the data stored in the memory.
·         Pointers are used to return the multiple values from a function via arguments .
·         Each location has a unique address .
Example :
int x ;
x = 10;
int *ptr;  /*    *ptr is a pointer variable pointing to an integer value */
·         “*” indicates that pointer variable ‘ptr’ contains address of variables .
·         The address should contain only integer type values .
ptr = &x;
            [&x is used to get the address]
Eg :
printf(“%d” , *ptr);
printf(“%d”, ptr);
printf(“%d”, &ptr);
Here , *ptr tells that the variable is a pointer .
·         Ptr tells the name of memory location and points to a variable .
·         &ptr tells us the address of variable .
POINTERS AND ARRAYS :
·         An Array name can be assigned to the pointer variable, because it contains the address of the first element.
·         When an array is declared the compiler allocates certain base address and storage in memory locations .
·         The base address is the location of the first element in an array .
·         For example : int x[5] = {1,2,3,4,5};
·         An array ‘x’ with size of 5 elements is declared and will be stored as follows .
·         Let us assume that the base address of ‘x’ is 100 then  , the remaining elements will be stored as follows :
 x =& x [1] = 1000+1 (no.of bytes required by    
                             the ‘int’ type )
                         = 1000+ 1(2) = 1002
If we declare ‘p’ as an integer pointer , as
int  *p;
p = x is equal to
p = & x [0]; ð p=& x [0] = 1000
                        P= & x [1] = 1002
                        P= & x [2]= 1004
                         P=& x [3] = 1006
                         P = & x [4] = 1008
POINTERS AND CHARACTERS :
·         Strings can be treated as character arrays .
·         The compiler automatically inserts the null character ‘\0’ at the end of the string .
·         Strings can be created using pointer variables .
Eg : char* str = “apple” ;
 Now , the string “apple” is stored as
·         The pointer ‘str’ points towards the first character  .  Assignment operator is used for giving values  .
 char *string1;
 String1 = “apple “;
·         The above statement is not a string copy because the variable ‘string1’ is a pointer not a stiring .
POINTERS AS FUNCTION ARGUMENTS :
·         We can pass the address of a variable as an argument to a function in the normal fashion.
·         When we pass addresses to a function ,  the parameters receiving the addresses should be pointers . the process of calling a function using pointers to pass the address of variables is known as “call by reference” .
·         The function which is called by ‘reference’ can change the value of the variable used in the call .
Consider the following code :
Main()
{
     int x ;
     x=20;
     change(&x);  /*call by reference or address*/
     printf(“%d\n”, x);
}
Change(int  *p)
{
*p = *p + 10 ;
}
·         When the function change() is called , the address of the variable x is passed into the function change() . Inside change() , the variable p is declared as a pointer and therefore p is the address of variable x .
·         Thus , call by reference provides a mechanism by which the function can change the stored values in the calling function .
·         Note that this mechanism is also known as “call by address” or “pass by pointers” .
·         Rules :
1)      The function parameters are declared as pointers .
2)      The dereferenced pointers are used in the function body.
3)      When the function is called the addresses are passed as actual arguments .
FUNCTION RETURNING POINTERS :
We can force a function to return a pointer to the calling function . consider the following code :
int *larger (int * , int *); /*prototype*/
main ( )
{     
  Int a = 10;
  Int b = 20;
  Int *p;
  p = larger (&a , &b);
  printf (“%d”, *p);     /*function call */
}
int *larger (int *x , int *y)
{
    if (*x>*y)
             return (x);   /*address of a */
    else
             return (y);   /*address of b */
}
·         The function larger receives the addresss of the variable a and b , decides which one is larger using the pointers x and y and then returns the address of its location . The returned value is then assigned to the pointer variable p in the calling function . In this case , the address of b is returned and assigned to p and therefore the output will be the value of b , namely 20 .
·         The address returned must be the address of a variable in the calling function.

POINTERS TO FUNCTIONS :
·         A function , lke a variable , has a type and an address location in the memory . It is therefore , possible to declare a pointer to a function , which can be used as an argument in another function .
·         A pointer to a function is declared as follows :
              type (*fptr)  ();
·         This tells the compiler that fptr is a pointer to a function , which returns type value . the value parentheses around *fptr are necessary . remember that a statement like
                 type *gptr();
·         Would declare gptr as a function returning a pointer to type
·         We can make a function pointer to point to a specific function by simply assigning the name of the function to the pointer . for example , the statements
                double mul(int, int);
                double (*p1) ();
                 p1 = mul;
·         Declare p1 as a pointer to a function and mul as a function and then make p1 to point to the function mul. To call the function mul , we may now use the pointer p1 with the list of parameters. That is ,
               (*p1)(x,y)  /*function call*/
Is equivalent to
                    mul(x,y);
POINTERS AND STRUCTURES :
The name of a structure stands for the addresses of the 0th element . consider the following declaration :
                      struct inventory
                      {
                               Char   name[30];
                                Int   number ;
                                Float price ;
                        }  product [2] ,   *ptr ;
Its members can be accesed using the following notation
            Ptr->name
             Ptr->number
             Ptr->price
The symbol ‘->’ is called arrow operator ( also known as “member selection operator”). Ptr -> is simply another way of writing product[0].
POINTER TO STRUCTURE VARIABLES :
While using structure pointers , we should take care of the precedence of operators . the operators ‘->’ and ‘.’ And () [] have the highest priority among operators. They bind very tightly with their operands . for example
 Struct
{
                  Int count ;     /*pointer inside the struct*/
                  Float  *p ;      /*struct type pointer*/
 }  *ptr ;
Then the statement
                  ++ptr -> count ;
Increments the count not ptr. However
                  (++ptr)  -> count ;
Is legal and increments ptr after accessing count .
The following statements also behave similarly ,
*ptr ->p        fetches whatever p points to
*ptr->p++     increments p after accessing whatever it points to
(*ptr->p)++          increments whatever p points to
*ptr++->p            increments ptr after accessing whatever it
                               points to