Linux Tips #17



---------------------------------------------------------------

If you like Tip of the Day please share it with friends and 
co-workers, and encourage them to sign up! It's free. You can
unsubscribe or change your e-mail address at any time.

To subscribe to or unsubscribe from this newsletter:
* Use your browser to visit our Newsletter Subscription Center:
  http://www.winmag.com/subscribe/
* Scroll down to the Tip of the Day section.
* Click "Choose an option," and select Subscribe or Unsubscribe.
* Scroll to the top of the page, and type your e-mail address 
  in the "E-mail" field.
* Click the Submit button below your e-mail address.

Copyright 2000 CMP Media Inc. A service of Winmag.com.
http://www.winmag.com/

Distributed by MessageMedia Inc. - http://www.messagemedia.com

---------------------------------------------------------------


*1. LINUX VIRTUAL SERVERS                 
        
A virtual server is a scalable and highly available server built on a 
cluster of real servers. The architecture of the cluster is 
transparent to the end users, who see only a single virtual server. 
Thus, a virtual server offers a very high computation power as well as 
exceptionally high fault tolerance. You can find more info on this 
technology and its uses at 

http://www.linuxvirtualserver.org/


*2. THE LINUX MICRO-CONTROLLER PORT                 
        
The uCLinux (Linux Micro-controller, the lowercase u stands for the 
Greek letter "mu") project is a port of Linux 2.0 to embedded systems 
that don't have a memory management unit. The end goal of this project 
is to port Linux to handheld devices and embedded controllers that do 
not have a built-in memory management unit. uCLinux is an Open Source 
product distributed under the GNU Public License. For further info, 
visit the uCLinux Web site at 

http://www.uclinux.org/


*3. STATICALLY LINKED KERNEL DEVICE DRIVERS                 
        
Device drivers can be compiled and linked directly into the kernel. 
This type of driver is called a statically linked device driver. Such 
a driver is integrated into the kernel image and remains attached to 
it until the next time the kernel is rebuilt. This is not the 
preferred technique of writing device drivers because you need to 
recompile, relink, and reinstall the kernel every time you want to 
add, remove, or update a device driver. Still, in older versions of 
Linux, this technique was rather popular.


*4. LOADABLE KERNEL MODULES                 
        
A Loadable Kernel Module (LKM) can be added and removed while the 
system is running. Modern device drivers are written as LKMs. This 
form is a significant improvement over statically linked kernel device 
drivers because it eliminates the need to recompile, relink, and 
reinstall the kernel every time you modify any of its supported device 
drivers. Another advantage of LKMs is that they are not subjected to 
the GPL licensing rules because they are not linked into the kernel 
image.


*5. LINUX KERNEL CRASH DUMP                 
        
The Linux Kernel Crash Dump project attempts to provide a more 
reliable method of examining system failures after the machine 
recovers. The project contains kernel and user level code that is 
designed to save kernel memory information when the system crashes due 
to a software failure. When the system is rebooted, the saved kernel 
memory information can be recovered and analyzed to determine the 
cause of the failure. The documentation, source code, and RPMs of 
Linux Kernel Crash Dump are now available at 

http://oss.sgi.com/projects/lkcd/


*6. THE RETURN STATUS OF MAIN()                 
        
When main() exits, either implicitly or explicitly (that is, by an 
explicit call to exit() or due to a return statement), it returns to 
the environment a status code that indicates successful or failed 
termination. Remember, though, that the return code is truncated to 
eight bits. Therefore, you should return only values in the range of 
-127 through 127.


*7. THE DIFF3 COMMAND                 
        
The diff3 is useful when two people change a common file and create 
two independent versions thereof. Diff3 compares the original file, as 
well as the two files derived from it, all at once. Diff3's syntax is 

diff3 derived1 originalfile derived2 

Where originalfile is the common ancestor from which derived1 and 
derived2 are derived.


*8. BASIC INLINE ASSEMBLY                 
        
Standard C and C++ enable you to embed inline assembly code in your 
program. The reserved keyword "asm" takes a quoted string that is a 
native assembly directive. For example: 

asm ("nop"); 

is a no-operation assembly directive, and 

asm ("cli"); 

disables all interrupts. The __asm__ token is identical to asm. You 
can use __asm__ instead of standard asm if the latter conflicts with 
other identifiers in your program. Still, it is best to stick to the 
standard asm keyword whenever possible to ensure compatibility with 
other compilers and UNIX versions.


*9. DYNAMIC ALLOCATION OF STACK MEMORY                 
        
The function alloca() allocates memory at runtime. Note, however, that 
unlike malloc() and calloc(), alloca() allocates memory from the 
stack, not from the heap. This is advantageous because the allocated 
memory is automatically released when the function that invoked 
alloca() exits. In the following example, alloca() is used to create a 
memory buffer that is automatically released when the function exits: 

int f() 
{ 
  char * p = (char *) alloca(12); /*allocate 10 bytes*/ 
  if (p!=NULL) 
    strcpy(p, "hello world"); 
}  /*memory is reclaimed automatically*/ 

Note that alloca() is not defined by ANSI C.


*10. BENEFITS OF RECOMPILING YOUR KERNEL                 
        
When upgrading your compiler, you may consider recompiling your 
kernel. The new compiler version may provide better optimizations and 
bug fixes so the overall performance gain can be significant. Note 
that this tweak is recommended for experienced users and that you 
should follow the documentation regarding kernel compilation that is 
included in your Linux distribution.