home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!ut-emx!tivoli!TIVOLI.COM!stuart
- From: stuart@TIVOLI.COM (Stuart Jarriel)
- Newsgroups: comp.sys.hp
- Subject: Re: attaching xdb to a running process...
- Message-ID: <3742@tivoli.UUCP>
- Date: 3 Sep 92 03:06:45 GMT
- References: <3739@tivoli.UUCP>
- Sender: news@tivoli.UUCP
- Organization: Tivoli Systems, Inc
- Lines: 58
-
- a 52 line program to illustrate the point...
-
- #include <sys/signal.h>
- #include <stdio.h>
-
- main(int argc, char *argv[])
- {
-
- int pid, pid1, pid2, i;
- int exitcode;
-
- printf("in main program\n");
-
- pid = fork();
-
- if (pid != 0) { /* parent */
- waitpid(pid, &exitcode, 0);
- exit(0);
- }
-
- /*
- * here is the child
- */
-
- printf(" in the child\n");
-
- pid1 = fork();
-
- if (pid1 != 0) { /* parent */
- pid2 = getpid();
- printf(" in the first child (debugger parent) %d\n", pid2);
-
- exec_debugger(argv[0], pid2);
-
- pause();
-
- printf("starting the loop\n");
- for (i=1; i < 100; i++) {
- printf("I is %d\n",i);
- }
- exit(1);
- }
- }
-
- exec_debugger(char *proc, int pid)
- {
- char pidstr[20];
-
- sprintf(pidstr,"%d",pid);
- printf("starting the debugger %s\n", pidstr);
-
- if (fork() == 0) {
- execlp("/usr/bin/X11/hpterm", "/usr/bin/X11/hpterm", "-display",
- "local:0", "-e", "/usr/bin/xdb", "-P", pidstr, proc,
- NULL);
- exit(2);
- }
- }
-