Nothing to cram, funda is simple as their names. Mono means everthing in kernel space.
Micro means very minimal in kernel space.
Mono what goes into the kernel (kernel space)
Process management, memrory management, file system, i/o services etc. e.g Linux kernel;
Micro Kernels what goes into the kernel
very minimal support for the process management goes into the kernel, everything else all above mentioned things are implemented in user space.
These services in user space are called as servers. kernel communicates with them with message passing(IPC). e.g QNX
The main disdvantage of monolithic kernels is the dependency between system components - a bug might crash the entire system - and the fact that large kernels also
become difficult to mantain.
Other disadvantages are the kernel size, lack of extensibility and the bad maintainability. Bug-fixing or the addition of new features means a recompilation of the whole
ernel. This is time and resource consuming because the compilation of a new kernel can take severalhours and alot of memory. Everytime someone adds a new feature or
xes a bug, it means recompilation of the whole kernel.
there are three kind of scope ( place in the code where variable can be accesed )
extern : entire prog auto : in the block where its defined. static : now there is a nice twist here in words. I will say if defined inside a funtion it has a auto scope. But it you define it before a function then it has a scope there after but only in the file where its defined.
Now its life time utill when variable is having life.... fundu haan :)
Not like that it simply means that point of time when variable can be accessed.
Unfortunatly there is no keyword as scope to define life time.
Life time of static and extern variable is before main is called and utill program exits. Life time of arguments and that of local variables it is from the point when funciton is called and untill function return. Life time of dynamic allocated block is from the point when we issue malloc or calloc command to the point when we use free call.
This can be easily explained why number of storage classes available in C language and some basic computer Science knowledge.
Code Segment
When we compile code we will get binary language code. These are the instructions to the processor what to do.
So to execute any program you need these instructions. These instructions will not change throughout you program. Processor needs to have these instruction in the RAM or in some cases of embedded system they can be directly read form the ROM (if byte addressable). That’s the reason to put them in a segment called Code or Text segment. Before executing the program this segment is copied to RAM and program starts executing by reading these instructions.
Data Segments (initialized variables)
C has provided global variables (for the time being consider initialized variables). Why to use global variable? Answer is very simple we want to have variable visible to entire program/file and more importantly they will retain their values throughout the program. Aren’t they required in RAM for full life span of program? Yes that’s why placed in the segment called data segment. Data segment is part of the object file as well as executable.
Initialized Static variables also has behavior they stay alive full span of program so are also placed in the data segment.
BSS (Un- initializedStatic/Global Variable)
Ok you want global variable but its not being initialized. As it doesn’t have any value associated till run time, why to waste the space in the object file/ executable. That’s the reason there is one more segment made called block started by symbol BSS where just the information about these kind of variable is stored. At run time appropriate memory is allocated to these types of variables.
Read Only data Segment
I something is const, how does file format will ensure that modification of such kind of data is prohibited and if you try to do so; compilation/runtime error is resulted. Very easy, file format store such kind of variables in a region which is read only. You can only modify the region value one time and that is during initializing. So all the constants, string literals are stored in this read only segment.
Heap Memory and Stack Memory
These are not the part of the executable/ object file. These are run time entities.
Where Const Variables are stored
Yeah this is very important question and to answer it in one sentence will be “implementation dependent”. Now one thing should be clear and that is difference between constant and read-only. To be honest term “constant variable” is oxymoron. Data can be constant a object can’t. Its pretty obvious if entity changes its value then that’s not a constant.
A variable can have cont qualifier in that case its just marked as read only. As I have told in one more post also “adding const qualifier to a variable is promises you make that variable will not change its value and it’s up to the compiler to keep this promise”. Const variable is marked as read only but there are still ways to breach that read-only hindrance.Want to have a proof in “C”
Look at this
Cont int a =20;
int *p=(int *)&a;
a=30; //Compilation erro
but
*p =30; will get through.
If you have noticed the above few lines carefully you can make out that const variables are not stored inrodata segment. They will go to stack only (if local).
Making any variable const does not change the place where variable is stored.
Its simply a request to the compiler that perticular variable will be used heavly and place it in CPU registers.
But there are lots of gotchas here
1) Which data can be held in registers depend on register size. Normaly its size of word or interger elemnet max. Though some system do have the registers capalbe of holding the floating point values in registers.
2) Though its a request but once you declare a variable as register it may go to the register. So you cannot use its address in your program. It means you can not use & operator on the register variable. If you try to do the same you are welcomed with compiler error.
3) More over you declared a variable regiter and system choose to put it in the register. It may actually slow down your system. Because no of registers are limited in numbers and you have reserved some of them, now the variable you have placed in the register is not modifying enough so its like wasting a resource.
4) You can ask when to use register type. Plain answer is never. In earlier days it was a value addtion to the 'C' language as earlier compiler were not using register at all implicitly. But mordern compilers are smart enough to decide which value is to be placed where. Actully its a rare event that by putting some value in register can increase the efficeny of your program.
Some of todays compiler simply ignore the register keyword as its perfecly inline with reiger definition "Its a request not an order".
Ok, So here I am with the most favorite topic of Computer programming industry.
What is the main difference in compiled code and that of executable code??
This is the question which even the experienced programmer don’t answer properly.
When asked you need to be little technical…
Ok when you compile the code a .o file is created. This is what we called compiled code (Rocket Science Funda Reveled ;)) …
And what you get after linking all the required object files is called executable file.
SO whats the difference ?
When you compile the code some references may not be present in the same file which you are compiling. But compiler recognizes that ( as it sees the declaration in .h file youmust have included in the file) from header file. Now this piece of code will not be available until run time, so normal jump instruction address can not be found at compile time. So Now what the compiler does is it leaves that jump filed empty and fills that at the run time… This is the main step which differentiate the object code and executable code. Jump instruction address are there in executable not in the object files…
Please note that that absolute address is even not know in the .exe file, it still does the guess work like 14 byes from beginning etc.
Main difference .o and .exe file is the jump address in the .o file is not known.