Linux Tips #6



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

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. GCC EXTENSIONS TO ANSI C: INLINE FUNCTIONS                 
        
Gcc, the standard compiler used with Linux, adds several
 extensions to ANSI C. Some of these extensions are now in the
 process of being added to the new ANSI C standard, the C9X.
 However, other extensions are Linux-specific. The following
 tips discuss some of these extensions and their usefulness. 

The first extension to be discussed is the keyword "inline". Many
 system-specific header files declare functions as inline. An
 inline function is expanded like a macro, thereby eliminating
 the overhead of a function call. In addition, inline functions
 provide all the type-checking available with ordinary function
 calls, so inline functions are both safe and efficient.


*2. GCC EXTENSIONS TO ANSI C: ATTRIBUTES                 
        
Another gcc extension is the keyword "attribute," which enables
 the programmer to provide more information about a function, a
 declaration, or a variable than is possible in strict ANSI C.
 The additional information can help the gcc compiler to produce
 more optimized code. In addition, attributes give the programmer
 tighter control over the generation of object code, which is
 impossible otherwise. For example, the attribute "noreturn"
 explicitly declares a function that does not return and
 instructs the compiler to suppress spurious warnings. Likewise,
 the "aligned" attribute tells the gcc compiler how exactly to
 align a type or a variable.


*3. GCC EXTENSIONS TO ANSI C: THE LONG LONG DATA TYPE                 
        
A new data type that is not part of ANSI C is long long. It is
 large enough to store a 64-bit integer. Since most Linux and
 Unix platforms are based on 32-bit architectures, long long
 variables are used for storing very large numbers that exceed
 the 32-bit limit. Similarly, unsigned long long can store a
 64-bit unsigned integer.


*4. ADVANTAGES OF SHARED LIBRARIES                 
        
Linux, like many other operating systems, supports shared
 libraries. A shared code library offers several advantages over
 a statically linked library. A shared library saves system
 memory because the system shares memory among all the processes
 that use the library, rather than allocating distinct memory
 buffers for each process. In addition, a shared library saves
 disk space because programs that use it do not contain distinct
 copies of the shared code. Finally, a shared library can be
 upgraded more easily because the processes that use it pick up
 the latest version of the library automatically when they run,
 whereas programs that use statically linked libraries have to be
 recompiled and linked.


*5. THE LINUX WAY OF CONCURRENCY                 
        
The Unix kernel switches context among threads faster than it
 does with full-blown processes. This is why programmers often
 prefer to use multithreading instead of multiprocessing. Linux,
 however, works differently than Unix in this respect. Its kernel
 performs context switches among processes significantly faster
 than the Unix kernel. Since multithreading has several inherent
 safety problems and since multiprocessing is simple and fast on
 Linux, you should consider using multiprocessing rather than
 multithreading to achieve concurrency on Linux.


*6. THE LINUX SOFTWARE MAP                 
        
If you are looking for a specific application for Linux, you can
 consult the Linux Software Map (LSM) at 

http://www.execpc.com/~lsm 

The LSM contains documentation of thousands of software products
 that are readily available for Linux users. The documentation
 includes product names, version numbers, a Web site where the
 product can be downloaded from, and other useful information.


*7. USING MANUAL PAGES                 
        
The command "man" activates the Linux Manual Pages (Man Pages)
 utility, which provides succinct reference documentation about
 system calls, devices, files, libraries, file formats, and
 others. To learn how to use man, simply type the command
 "man man" and follow the instructions.


*8. LINUX FILE SYSTEM--THE FILE MODE                 
        
On Linux, every file is associated with a 16-bit integer that
 represents the file's type and its access permissions. This
 small integer is called the "file mode." The file mode usually
 appears as a sequence of six octal digits; the low order three
 digits represent the file access, the next digit contains file
 permissions, and the last two digits represent the file type.
 For example, the file mode 0041755 (note: the first zero
 indicates an octal number and is not included in the file mode)
 indicates a file type 04, a permission modifier of 1, and access
 permissions of 0755. The file mode can be altered to control
 what processes may access the file.


*9. LINUX FILE SYSTEM--CATEGORIES OF FILE USERS                 
        
Linux defines three categories of file users: the file owner, the
 group of the file owner, and, finally, all other users. The term
 "world permissions" refers to permissions that are granted to
 all these three categories. The file access permissions contain
 three digits, each of which corresponds to one of the
 three categories.


*10. THE NOTION OF TIME                 
        
Linux, like all Unix systems and many other operating systems,
 refers to midnight, January 1, 1970, Universal Time Coordinated
 (which is roughly equivalent to Greenwich Mean Time) as its
 baseline for time measurements. Midnight, January 1, 1970, is
 also called "the epoch." The time on Linux systems is
 represented as a long integer that contains the number of
 seconds elapsed since the epoch.
