From: Michael Elizabeth Chastain <mec@shout.net>
To: aurelien.chanudet@enst.fr, gdb@sources.redhat.com
Subject: Re: process attaching gdb to itself
Date: Sun, 28 Sep 2003 22:35:00 -0000 [thread overview]
Message-ID: <200309282225.h8SMP9Rf026649@duracef.shout.net> (raw)
Hello,
char cmd [256];
sprintf (cmd, "gdb attach %d", getpid ());
system (cmd);
'system' waits for the program that it calls to finish.
Thus, your program is waiting for gdb to finish before it
does anything.
Try the appended program which uses raw fork/exec.
It works for me on red hat linux 8, native i686-pc-linux-gnu.
If you try to do this in production code then you are likely
to run into a blizzard of race conditions, error cases,
and signal handling problems. If you are doing this as a learning
experience, that's great -- read up on 'man fork' and
'man execlp', and check out a book on Linux systems programming.
Michael C
GDB QA Guy
===
#include <stdio.h>
int main ()
{
int pid = fork ();
if (pid == -1)
{
/* error */
fprintf (stderr, "fork error\n");
exit (2);
}
if (pid != 0)
{
/* parent process */
char spid [256];
sprintf (spid, "%d", pid);
execlp ("gdb", "gdb", "a.out", spid, NULL);
/* execlp returns only if error */
fprintf (stderr, "execlp error\n");
_exit (2);
}
/* child process */
sleep (5);
printf ("hello hacker\n");
return 0;
}
next reply other threads:[~2003-09-28 22:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-28 22:35 Michael Elizabeth Chastain [this message]
2003-09-28 22:45 ` Andrew Cagney
2003-09-29 2:21 ` Daniel Jacobowitz
2003-09-29 13:23 ` Andrew Cagney
2003-09-29 13:30 ` Daniel Jacobowitz
2003-09-29 14:54 ` Andrew Cagney
2003-09-29 14:59 ` Daniel Jacobowitz
-- strict thread matches above, loose matches on Subject: below --
2003-09-28 20:45 Aurelien Chanudet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200309282225.h8SMP9Rf026649@duracef.shout.net \
--to=mec@shout.net \
--cc=aurelien.chanudet@enst.fr \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox