This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Pipe question


Hi to all!

First, I want to thank Eli Zaretskii, Jim Blandy, Kris Warkentin, Keith 
Seitz and Joel Brobecker for their advices about communication with GDB.

Now, a question. I\'m doing this:

    pipe(togdb); pipe(fromgdb);
    if (fork() != 0)
    {
        close(togdb[0]);
        close(fromgdb[1]);
    }
    else
    {
        /* This is necessary for my GUI */
        int Max = sysconf(_SC_OPEN_MAX);
        for (int i=STDERR_FILENO+1;i<Max;i++)
            fcntl(i, F_SETFD, FD_CLOEXEC);

        close(togdb[1]);
        dup2(togdb[0],0);
        close(fromgdb[0]);
        dup2(fromgdb[1],1);
        system(strcat(\"gdb --quiet -f \",executable));
    }

When I want to give GDB a command, I write in togdb[1]; when I want to 
parse GDB output, I read from fromgdb[0]. All is working. (Note: system
() is exec()).

But when I close the program, I only write \"quit\\n\" to togdb[1]. This 
causes that the program doesn\'t end properly (GDB, which is the child 
process, ends well). I have to go and type \"kill\" in a console. Could 
anybody tell me what instructions I have to put in the end of the 
program in order to finish it succesfully (without kill)? I suppose 
it\'s something related with the pipes...

Thanks in advance.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]