Fortune

Ξ May 12th, 2008 | → 0 Comments |
Humor |, , , |

A Tale of Two Cities LITE(tm)
– by Charles Dickens

A lawyer who looks like a French Nobleman is executed in his place.

The Metamorphosis LITE(tm)
– by Franz Kafka

A man turns into a bug and his family gets annoyed.

Lord of the Rings LITE(tm)
– by J. R. R. Tolkien

Some guys take a long vacation to throw a ring into a volcano.

Hamlet LITE(tm)
– by Wm. Shakespeare

A college student on vacation with family problems, a screwy
girl-friend and a mother who won’t act her age.

by fortune(6)

 

Handling SIGSEGV Signal

Ξ May 9th, 2008 | → 0 Comments |
Development |, , , , |

Soon or later, your Linux developed C/C++ code will generate a SISEGV signal and your application will miserably crash. This signal is generated when a program tries to read or write outside the memory that is allocated for it, or to write memory that can only be read. (Actually, the signals only occur when the program goes far enough outside to be detected by the system’s memory protection mechanism.) The name is an abbreviation for “segmentation violation”.

In order to improve your program, and terminate in a controlled way, you can register a custom function to handle such signal. The following example shows the leave function that is called whenever a SIGSEGV signal is launched.

    #include

    #include

    void leave( int s ) {
        std::cout << "FATAL: Leaving due to SIGSEGV." << std::endl;
        exit( s );
    }

    int main() {
        // Register SIGSEGV handler!
        signal( SIGSEGV, leave );

        // originate a SIGSEGV
        double array[20];
        std::cout << array[10000] << std::endl;

        return 0;

    }