In: Computer Science
How large is an operating system? Choose an example system, and count the lines of source code used for the kernel
Operating System (OS)
An OS is a system software which manages the hardware and software
resources of a computer and gives the services for programs.
Kernel is the core of a OS, which controls everything in the system. Kernal is the first programs that loaded in the system after the boot loader loads. The kernal will handle the I/O requests from the software, converting it into executable instructions for the the processor. It will monitors the memory and also the peripherals such as keyboards, monitors, printers, keyboards and speakers.There will be critical code for the kernal which will be stored in the separate area of memory. The critical code will be s protected from other external accessing. The kernel has to handle the tasks such as executing different processes, controlling the hard disk, interrupts handling operations etc..
For this we have take an example of Windows Operating System
How large is a Windows operating system??
This question depends on different parameter: one important parameter is line of source code used by the kernal. The source code consists of comments, executable code, non executable codes, non delivered codes, statements etc..
Windows kernel have approximately 1.7 million lines of source
code.
for example :
#include "console.h"
#include "serial.h"
#include "graphics.h"
#include "kmalloc.h"
#include "string.h"
struct console {
struct_grhs *gphx;
int x_size;
int y_size;
int x_post;
int y_post;
int on_off;
int ref_cnt;
};
struct console console_root = {0};
static struct graphics_color bgmcolor = { 0, 0, 0 };
static struct graphics_color fgmcolor = { 255, 255, 255 };
static void console_reset( struct console *d )
{
if(!d || !d->gphx) return;
d->x_post = d->y_post = 0;
d->x_size = gra_wid(d->gphx) / 8;
d->y_size = gra_ht(d->gphx) / 8;
d->on_off = 0;
graphics_fgmcolor(d->gphx, fgmcolor);
graphics_bgmcolor(d->gphx, bgmcolor);
graphics_clear(d->gphx, 0, 0,gra_wid(d->gphx),
gra_ht(d->gphx));
}
void console_heartbeat( struct console *d )
{
char c = d->on_off ? ' ' : '_';
graphics_char(d->gphx, d->x_post * 8,
d->y_post * 8, c );
d->on_off = !d->on_off;
}
int console_write( struct console *d, const char *data, int size
)
{
graphics_char(d->gphx, d->x_post * 8,
d->y_post * 8, ' ');
int i;
for(i = 0; i < size; i++) {
char c = data[i];
switch (c) {
case 13:
case 10:
d->x_post =
0;
d->y_post++;
break;
case '\f':
d->x_post =
d->y_post = 0;
d->x_size
=gra_wid(d->gphx) / 8;
d->y_size =
gra_ht(d->gphx) / 8;
graphics_fgmcolor(d->gphx, fgmcolor);
graphics_bgmcolor(d->gphx, bgmcolor);
graphics_clear(d->gphx, 0, 0,gra_wid(d->gphx),
gra_ht(d->gphx));
break;
case '\b':
d->x_post--;
break;
default:
graphics_char(d->gphx, d->x_post * 8, d->y_post * 8,
c);
d->x_post++;
break;
}
if(d->x_post < 0) {
d->x_post =
d->x_size - 1;
d->y_post--;
}
if(d->x_post >=
d->x_size) {
d->x_post =
0;
d->y_post++;
}
if(d->y_post >=
d->y_size) {
d->x_post =
d->y_post = 0;
d->x_size
=gra_wid(d->gphx) / 8;
d->y_size =
gra_ht(d->gphx) / 8;
graphics_fgmcolor(d->gphx, fgmcolor);
graphics_bgmcolor(d->gphx, bgmcolor);
graphics_clear(d->gphx, 0, 0,gra_wid(d->gphx),
gra_ht(d->gphx));
}
}
graphics_char(d->gphx, d->x_post * 8,
d->y_post * 8, '_');
return i;
}
void console_putchar( struct console *c, char ch )
{
console_write(c,&ch,1);
}
void console_putstring( struct console *c, const char
*str)
{
console_write(c,str,strlen(str));
}
struct console *console_create(struct_grhs *g)
{
struct console *c = kmalloc(sizeof(*c));
c->gphx = graphics_add(g);
c->ref_cnt = 1;
console_reset(c);
return c;
}
struct console *console_addref( struct console *c )
{
c->ref_cnt++;
return c;
}
void console_delete( struct console *c )
{
c->ref_cnt--;
if(c->ref_cnt==0) {
graphics_delete(c->gphx);
kfree(c);
}
}
void console_size( struct console *c, int *x_size, int *y_size
)
{
*x_size = c->x_size;
*y_size = c->y_size;
}
struct console * console_init(struct_grhs *g)
{
console_root.gphx = g;
console_reset(&console_root);
console_putstring(&console_root,"\nconsole:
initialized\n");
return &console_root;
}
This is a 150 line of source having 3KB size