Sunday, 24 April 2011

Defining Classes

Defining  Classes

The  basic  structure   of   defining   a   class   is   as   follows :

scope   class   className [extends  class]
{
//class   implementation  statements 
}

When   declaring   the  scope  of  the  class  ,  we  have  several   options  to   control  how  other   classes   can   access  this  class:

public  ---   the  class   can  be  used  by  code   outside   of   the   file .  only  one  class   in  a  file   may   have   this  scope  .  The   file  must   be  named   with   the  class   name  followed   by   the   four-letter   .java    extension.

private  --- the   class  can  only  be   used  by   itself   and   must   be   subclassed  .

The Context Of A Process

The  Context  Of   A   Process

The   context   of   a   process   consists   of  the  contents   of   its (user)  address  space   and   the  contents   of  hardware   registers  and  kernel   data  structures   that   relate   to   the  process . Formally  the   context   of   a  process   is   the   union  of   its   user - level   context , register  context  and  system  level  context  .  The   user - level  context  consists   of   the   process   text  ,  data ,  user   stack ,  and  shared   memory  that   occupy  the   virtual   address   space   of   the   process  .  Parts   of   the   virtual   address  

Sample Interrupt Vector

Sample  Interrupt   Vector

Interrupt  Number                 Interrupt  Handle
0                                              clockintr
1                                              diskintr
2                                              ttyintr
3                                              devintr
4                                              softintr
5                                              otherintr

Algorithm for Handling Interrupts

Algorithm  for  Handling  Interrupts

algorithm  inthand   /*  handle   interrupts  */
input  :  none
output  :  none
{
save (push) current   context   layer  ;
determine  interrupt  source ;
find  interrupt   vector;
call   interrupt  handler ;
restore (pop) previous  contex  layer

}

Algorithm for system calls

Algorithm   for   system  calls  /*  algorithm   for  invocation   of   system   call */
input  : system   call  number
output  :  result  of  system   call
{
find   entry   in  system   call   table  corresponding   to  system   call  number ;
determine   number   of   parameters   to   system   call ;
copy  parameters   from   user   address   space  to  u  area ;
invoke  system   call  code   in  kernel  ;
if (error   during   execution   of  system  call )
{
set   register   0  in  user   saved   register   context   to   error   number ;
turn   on   carry   bit   in  PS   register  in  user  saved   register  context;
}
else 

set   registers   0 ,1  in   user   saved   register   context  to  return   values   from   system   call ;
}

Algorithm allocreg

Algorithm  allocreg   /*  allocate  a  region   data  structure */

input :  (1) inode  pointer
(2) region   type
output :  locked  region
{
remove   region  from   linked   list  of   free   regions ;
assign   region  type ;
assign   region  inode  pointer ;
if(inode  pointer   not   null)
                 increment    inode   refernce  count ;
place  region  on  linked   list  of   active  region ;
return (locked   region);
}

Alogithm Growreg for changing the size of a Region

Alogithm   Growreg  for   changing   the   size  of   a   Region


algorith   growred  /*  change   the   size   of   a   region  */
input : (1) pointer    to  per   process  region   table   entry 
(2)  change   in   size   of  region (man   be   positive   or   negative)
output:   none
{
if(region   size   increasing)
{e
check  legality  of  new  region  size ;
allocate   auxiliary   tables(page   tables);
if(not   system  supporting  demand   paging)
{
allocate   physical   memory ;
initialize  auxiliary  tables , as  necessary ;
}
}
else  /*  region   size  decreasing */
{
free  physical  memory ,  as  appropriate ;
free  auxiliary  tables ,  as  necessary ;
}

do (othere) initialization  of  auxialiary  tables  ,  as   necessary ;
set   size  field   in  process  table;
}

Saturday, 23 April 2011

Algorithm for allocating a Region

Algorithm   for   allocating   a   Region

algorithm   allocreg  /*   allocate    a   region   data   structure  */
input  : (1) inode   pointer
(2)  region   type
output : (1) locked   region
{
remove   region   from   linked   list   of   free   region ;
assign   region   type ;
assign   region   indoe  pointer ;
if (inode   pointer   not  null)
increment   inode   reference   count ;
place  region   on  linked   list   of  active  regions ;
return(locked  region);
}

algorithm attachreg

algorithm   attachreg       /*  attach  a   region   to  a   process*/
input : (1)  pointer  to  (locked)  region  being   attached
(2)  process   to   which   region   is   being   attached  
(3)  virtual   address   in   process  where   region  will  be  attached 
(4)  region   type
output :  per   process  region   table   entry 
{
allocate  per   process  region  table   entry   for   process ;
initialize   per   process   region  table  entry ;
set   pointer   to   region   being   attached  ;
set  type   field  ;
set   virtual   address  field ;
check  legality   of  virtual   address  ,  region  table ;
increment   region  reference  count ;
increment   process   size  according   to  attached   region;
initialize   new   hardware   register   triple   for  process ;
return (per  process  region   table   entry );

}

Conversion of Byte Offset to Block Number in File System

Conversion of  Byte  Offset  to  Block  Number  in  File  System

algorithm   bmap /* block  map  of  logical  file  byte  of  offset   to  file  system block*/
input : (1) inode
(2) byte  offset

output: (1) block number  in  file  system
(2) byte  offset  into  block
(3) byte  of  I/O  in  block
(4) read  ahead  block  number

{
calculate  logical  block  number in  file  from  byte  offset ;
calculate  start   byte  in  block  for   I/O ;
calculate  number   of  bytes  to   copy  to  user ;
check  if  read  - ahead  applicale ,  mark  inode ;
determine  level  of  indirection  ;
while( not  at  necessary  level  of  indirection)
{
calculate  index  into  inode  or  indirect  block  from logical  block  number  in  file ;
get  disk  block  number  from  inode  or  indirect   block  ;
release  buffer  from   previous   disk  read , if  any  (algorithm  brelease );
if(no  more  levels  of   indirection)
return(block   number);
read   indirect   disk  block(algorithm  bread);

adjust   logical   block  number  in  file  according  to  level  of  indirection ; 

}
}



Disk Inode

Sample   Disk   Inode



owner  mjb
group  os
type  regular  file
perms   rwxr-xr-x
accessed  Oct 23 1984  1:45 P.M.
modified  Oct  23 1984  10.30 A.M.
inode  Oct 23 1984  1.30  P.M.
size   6030 bytes
disk   addresses 


Difference between Java And C/C++

Difference   between   Java  And  C/C++

Data  Types
  • All  java  primitives   data  types  (char , int , short , long , byte, float , double and  boolean ) have  specified  sizes  and   behaviour  that   are   machine-independent .
  • Conditional   expression   can  only  be  boolean , not  integral  .
  • Casting  between   data  types  is  much  more  controlled   in  Java . Automatic   conversion   occurs  only  when   there  is  no  loss  of   information   .  All   other  casts  must   be  explicit .
  • Java   supports   special   methods   to  convert   values   between  class  objects  and  primitive  types . 
  • Composite  data   types  are  accomplished   in  java   using   only  classes  .  Structures   and  unions   are   not   supported  .

Java Keywords

Java  Keywords

Class  organisation  -  package  -  
specifies   the  class  in  a  particular  source  file  should   belong   to  the  named   package .

import --  requests  the  named   class   or  classes   be  imported   into   the  current  applications  .

Class  definations  --  interface --
defines  global  data  and   method  signatures  that  can  be  shared  among  classes .

class --  defines   a   collection   of   related   data   behavior .

extends  --  indicates   which   class   to  subclass  . 
implements  -- indicates   the  interface  for  which  a  new  class   will  supply   methods .


Program that creates a new process to copy files

Program  that creates  a  new   process   to   copy   files


main(argc,argv)
int argc;
char *argv[];
{
/* assume  2  args ;  source  file  and  target   file*/
if(fork()== 0)
execl("copy","copy",argv[1],argv[2],0);
wait((int *) 0);
printf("copy done\n");
}


Explanation  :-



Program to copy a file

Program to  copy a file

#include<fcntl.h>
char buffer[2048];
int  version=1;

main(argc,argv)
int argc;
char *argv[];
{
int fold,fdnew;

if(argc!=3)
{
 printf("need 2 arguments for copy program\n");
exit(1);
}



fdold=open(argv[1],O_RDONLY);
if(fdold==-1)
{
printf("cannot open file %s\n",argv[1]);
exit(1);
}

fdnew=creat(argv[2],0666);
if(fdnew==-1)
{
printf("cannot create  file  %s\n",argv[2]);
exit(1);
}

copy(fdold,fdnew);

exit(0);

}


copy(old,new)
int  old,new;
{
int count;
while((count=read(old,buffer,sizeof(buffer)))>0)
write(new,buffer,count);
}