Thread: segmentation fault!!

  1. #1
    Registered User
    Join Date
    Jan 2008

    segmentation fault!!

    Hi!. I had a problem with a program in C++ using OCCI libraries. The program runs OK while is "running", but if I put in the console ctlr-c appears a message "segmentation fault" is the code.

    #include <string.h>
    #include <stdlib.h>
    #include <iostream>
    #include <occi.h>
    extern "C"
    #include "sql_def.h"
    using namespace oracle::occi;
    using namespace std;
          char *sUserDB,*sPswdDB,*idDB;
          Environment *env;
          Connection *con;
    int db_connect(char *Usr, char *Pswd, char *Sid)
      sUserDB = Usr;
      sPswdDB = Pswd;
     idDB  = Sid;
      cout << "Conectando a la BD."<< endl;
      env = Environment::createEnvironment();
        if (*idDB == 0)
          con = env->createConnection(sUserDB,sPswdDB);
          con = env->createConnection(sUserDB,sPswdDB,idDB);
        return 0;
      catch(SQLException &ex)
         cerr <<ex.getErrorCode() << ": " << ex.getMessage() << endl;
         return -1;
    int db_disconnect()
       cout << "Desconectando la BD." << endl;
       return 0;
    int main(int argc, char* argv[])
     int a = 0;
     cout << "salir:" << endl;
     cin >> a;
     return 0;
    it's a very simple code...thanks

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    What OS?
    At what point in the code is Ctrl-C pressed? Connect, disconnect, or input?
    What do you want it to do when Ctrl-C is pressed?

    If it's during connect or disconnect, you'll need to check the documentation on how signals are handled - if at all.


  3. #3
    Registered User
    Join Date
    Jan 2008
    The OS is linux (I don't know what distribution).

    I press ctrl-c to kill the process. At this moment the process dies but display on the screen a message "segmentation fault".

    I think that in the createEnvironment could be the problem. I put

    as parameter and works...but I don't know if that's is the bes thing that i can do.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    It may not help that much, but if you build your with debug (-g), then do "gdb myapp" and follow your steps to reproduce the problem, you should be able to see the call-stack using "backtrace <n>" to show the last <n> items of the stack (e.g. backtrace 10 will show ten call levels).

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault problem
    By odedbobi in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2008, 03:36 AM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM