Thread: sqlite_open & system function imcompatibility

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    13

    sqlite_open & system function imcompatibility

    I am having two commands they are:


    1.sqlite_open() //to open the database.
    2.system() //to call any system functions.

    I want to use these functions in one single application but they don't work along each other they always hang each other and hang the application at the time of execution.
    they work perfect separately but when they are write one after another they hang the application while executing.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Without some example code, your description is meaningless.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    There is nothing wrong with using those 2 functions together in an application. The problem is probably with the way you are using the functions -- not the functions themselves.
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #4
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Agreed; need to see what you are trying to do with them. They are totally unrelated. PS3 uses SQLite all the time without issue....system() not so much because there are far more graceful ways of gettings something done that that although I did once (as a joke) have it shell out with system to play a joke MP3 file but that is another story...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    13
    the sample code is:
    Code:
    main()
    {
    ret=open_sqlite("/mnt/jffs2/atm.db");// the name of the database
    
    ppp_open();//function to open ppp port to send the data.
    
    
    }
    //the defination of these two functions
    
    int open_sqlite(char *db_name)
    {
        if(sqlite3_open(db_name, &db_conn) == SQLITE_OK)
        {
    	printf("database opened \n");
            return 1;
        }
        else
            return 0;
    }
    
    
    int ppp_open()
    {
    int fd9,i,j;
    printf("PPP starting\n");
    printf("PPP something\n");
    ret=system("rm -f /var/run/ppp.link");
    printf("\nreturn of system ppp.link::: %d",ret);
    ret=system("/etc/ppp/dialout&");// the command to run the dailup function from the device.
    printf("\nreturn of system dialout::: %d",ret); 
    sleep(10);
    printf("\nppp_open\n");
    sleep(5);
    i=0;
    while (i<20)
            {
            fd9=open("/var/run/ppp.link",O_RDONLY);
    		printf("inside ppp_open :::::fd9 = %d\n",fd9);
    		if (fd9 > 0)
                    {
    				printf("\nNext to close\n");
                    close(fd9);
                    break;
                    }
    		printf("i = %d\n",i);
            sleep(1);
            i++;
            }
            if(i>=20)
               {
    			    ppp_close();
    				printf("\nppp closed\n");
                    return -1;
                    }
            printf("\nPPP Connected \n");
          
    	 
    		sleep(2);
            
    
            return 0;
    }
    this functions need to be executed in one application but one of these is always hangs up at the time of execution.


    thanks for quick response[/QUOTE]

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    First step is post something which is half-way decently indented if you want people to look at it.
    Code:
    main()
    {
      ret=open_sqlite("/mnt/jffs2/atm.db");// the name of the database
      ppp_open();//function to open ppp port to send the data.
    }
    
    //the defination of these two functions
    
    int open_sqlite(char *db_name)
    {
      if(sqlite3_open(db_name, &db_conn) == SQLITE_OK)
      {
        printf("database opened \n");
        return 1;
      }
      else
      return 0;
    }
    
    
    int ppp_open()
    {
      int fd9,i,j;
      printf("PPP starting\n");
      printf("PPP something\n");
      ret=system("rm -f /var/run/ppp.link");
      printf("\nreturn of system ppp.link::: %d",ret);
      ret=system("/etc/ppp/dialout&");// the command to run the dailup function from the device.
      printf("\nreturn of system dialout::: %d",ret); 
      sleep(10);
      printf("\nppp_open\n");
      sleep(5);
      i=0;
      while (i<20)
      {
        fd9=open("/var/run/ppp.link",O_RDONLY);
        printf("inside ppp_open :::::fd9 = %d\n",fd9);
        if (fd9 > 0)
        {
          printf("\nNext to close\n");
          close(fd9);
          break;
        }
        printf("i = %d\n",i);
        sleep(1);
        i++;
      }
      if(i>=20)
      {
        ppp_close();
        printf("\nppp closed\n");
        return -1;
      }
      printf("\nPPP Connected \n");
        
      sleep(2);
      
      return 0;
    }
    Next tell us EXACTLY what you see on screen. A terminal log would be ideal.

    Consider using the script utility to make a log.
    Code:
    SCRIPT(1)                                                        BSD General Commands Manual                                                       SCRIPT(1)
    
    NAME
         script - make typescript of terminal session
    
    SYNOPSIS
         script [-a] [-c COMMAND] [-f] [-q] [-t] [file]
    
    DESCRIPTION
         Script makes a typescript of everything printed on your terminal.  It is useful for students who need a hardcopy record of an interactive session as
         proof of an assignment, as the typescript file can be printed out later with lpr(1).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    I second script; it is an invaluable tool...I use it alot...that and screen are two of my best friends...well find and grep are OK too...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  8. #8
    Registered User
    Join Date
    Jan 2010
    Posts
    13
    I can give you the log file


    after running it happens like that

    log file starts:

    database opened

    ppp starting
    ppp something
    //at this point it hangs
    after pressing ctrl+c it returns
    the return of system ppp link::: 2
    the return of system ppp dail::: 2

    bash.//

    and here i return back to bash prompt

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    system() is NOT a fully fledged command line processor.
    If it accepts & at all, it will need a space after it.

    The fact that it returns 2 is a sign of trouble, not success.

    You'd be better off learning about unlink() to remove files, and fork() / exec() for creating a background process.
    Code full of calls to system() is little better than writing a batch file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Oh, and using the "report post" feature to attract attention to your post will almost certainly NOT help your cause.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Jan 2010
    Posts
    13
    Quote Originally Posted by Salem View Post
    Oh, and using the "report post" feature to attract attention to your post will almost certainly NOT help your cause.
    using a "report post" is not an intentional measure.

    thanks for reply.....i will try this function.

  12. #12
    Registered User
    Join Date
    Jan 2010
    Posts
    13
    sir,
    I had treid these command they are not working ....
    if there is mistake in calling procedure ....then please advice
    do i need to usesignals ,threads kind of anything

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > ret=system("rm -f /var/run/ppp.link");
    This would be
    Code:
    unlink( "/var/run/ppp.link");
    > ret=system("/etc/ppp/dialout&");
    This would be
    Code:
    if ( fork() == 0 ) {
      execl( "/etc/ppp/dialout", "/etc/ppp/dialout", (char*)0 );
    }
    Next time, try to be more constructive than "It doesn't work".
    WHAT did you actually try, and what effect did you see (if anything).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #14
    Registered User
    Join Date
    Jan 2010
    Posts
    13
    the command sqlite3_open() is sensitive to fork().
    if i use fork then after sqlite3_open() it will not work it just comes out of the application and the control comes to
    bash.//

    if I use execl alone the it doesn't execute the the command it creates new process leaving the previous process and after executing

    execl( "/etc/ppp/dialout", "/etc/ppp/dialout", (char*)0 );

    it comes out of the application and doesnt stay in application for the execution of further commands..........
    Last edited by er.rohan88; 01-15-2010 at 03:07 AM.

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Perhaps you need to do all the fork() / system() stuff before calling sqlite3_open

    Perhaps there is a DB connection which is established, that also gets into the sub-processes as well (and interferes with the connection in the parent process).

    Does each work independently?

    Can you fork() a trivial process (like /bin/false) and still maintain a DB connection?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  4. Replies: 4
    Last Post: 06-13-2005, 09:03 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM