Understanding the Kernel

Posted August 22, 2008 at 12:41 pm in Programming

The kernel is a program that constitutes the central core of a computer operating system. It has complete control over everything that occurs in the system.

The kernel is the first part of the operating system to load into memory during system startup, and it remains there for the entire duration of the computer session because its services are required continuously.

The kernel code is usually loaded into a protected area of memory due to its critical nature. This prevents it from being overwritten by other, less frequently used parts of the operating system or by application programs.

It provides basic services for all other parts of the operating system, typically including memory management, process management, file management and I/O (input/output) management.

The contents of a kernel vary considerably according to the operating system, but they typically include:

  1. A scheduler, which determines how the various processes share the kernel’s processing time (including in what order).
  2. A supervisor, which grants use of the computer to each process when it is scheduled.
  3. An interrupt handler, which handles all requests from the various hardware devices that compete for the kernel’s services.
  4. A memory manager, which allocates the system’s memory addresses among all users of the kernel’s services.

Reference: The Linux Information Project

Read More | Comment

Perl Fundamentals

Posted August 21, 2008 at 10:46 pm in Programming

Perl started out as the “Swiss army knife” of computer languages and was used primarily by system administrators, but over time it’s grown into an immensely robust language used by web-developers and programmers worldwide.

The Comprehensive Perl Archive Network is a great resource for already developed Perl modules. More than likely someone has created a module to perform the task you’re trying to accomplish.

Perl programs should start with the following line of code:

#!/usr/bin/perl

This line of code passes the rest of the code to the Perl interpreter, which is located at /usr/bin/perl (depends on your configuration).

A Perl comment uses #.

Arithmetic operators in order of precedence: EXPONENT **, (Unary Minus), MULTIPLY *, DIVISION /, ADD +, and SUBTRACT -. The MODULO % operator has the same precedence as * and /.

Bitwise operators are: AND &, OR |, XOR ^, and NOT ~.

Comparison operators: EQUAL TO ==, NOT EQUAL TO !=, LESS THAN <, GREATER THAN >, LESS THAN OR EQUAL TO <=, and GREATER THAN OR EQUAL TO >=.

Balance operator: <==>. This operator will point to the smaller number by indicating a 1 if the smaller number is on the right, -1 if the smaller number is on the left, or 0 if they are equal. Think of it like a number line as the arrows represent numbers increasing and decreasing to infinity and the equal signs representing the line, < -1 = 0 = 1 >.

Boolean operators: AND &&, OR ||, and NOT !.

Read More | Comment

Endianness

Posted August 19, 2008 at 3:56 pm in Programming

Endianness is the attribute of a system that indicates whether integers are represented from left to right or right to left, just like human languages. This may sound odd but if you’ve ever tried to read a book in English and another book in Japanese, you’ll notice that one flows from left to right and another from right to left. If you tried to read the book in Japanese from left to right, you would spend a lot of time attempting to decipher what that book was about.

There are two types of endianness, big and little. Big endian representation is in the left to right fashion and has the left most byte set as the most significant byte (MSB) in a multibyte integer. A simple example is the real number 200. The 2 on the left side indicates that this number is much larger than the number 100. We often learn the binary number system in big endian representation. Little endian representation is in the right to left fashion and has the right most byte set as the most significant byte in a multibyte integer.

Big endian most significant byte of any multibyte data field is stored at the lowest memory address. Little endian means that the least significant byte of any multibyte data field is stored at the lowest memory address.

An easy way to remember these is to think about input to a device. A big endian implementation would require the “big end” (MSB) first while a little endian implementation would require the “little end” first.

Endianness is important to processors as they attempt to read binary data from memory. Intel’s 80×86 is a common little endian processor. Sun’s Java Virtual Machine uses a big endian representation. Endianness is also important to network stacks and the communication field in general. Communicating devices must use the same endian implementation or they will not be able to communicate.

All of the protocols in the TCP/IP suite are big endian and as such, big endian is also known as Network Byte Order which requires the MSB first. Specifically, sin_port and sin_addr members of the sockaddr_in structure must use the big endian implementation when creating network sockets.

Read More | Comment

Page 4 of 41234