This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Pipe question
- From: a2782 at dis dot ulpgc dot es
- To: gdb at sources dot redhat dot com
- Date: Wed, 4 Dec 2002 14:36:36 GMT
- Subject: Pipe question
- Reply-to: a2782 at dis dot ulpgc dot es
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.