home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / hp / 9994 < prev    next >
Encoding:
Text File  |  1992-09-02  |  1.3 KB  |  70 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!ut-emx!tivoli!TIVOLI.COM!stuart
  2. From: stuart@TIVOLI.COM (Stuart Jarriel)
  3. Newsgroups: comp.sys.hp
  4. Subject: Re: attaching xdb to a running process...
  5. Message-ID: <3742@tivoli.UUCP>
  6. Date: 3 Sep 92 03:06:45 GMT
  7. References: <3739@tivoli.UUCP>
  8. Sender: news@tivoli.UUCP
  9. Organization: Tivoli Systems, Inc
  10. Lines: 58
  11.  
  12. a 52 line program to illustrate the point...
  13.  
  14. #include <sys/signal.h>
  15. #include <stdio.h>
  16.  
  17. main(int argc, char *argv[])
  18. {
  19.  
  20.     int pid, pid1, pid2, i;
  21.     int exitcode;
  22.  
  23.     printf("in main program\n");
  24.  
  25.     pid = fork();
  26.  
  27.     if (pid != 0) {        /* parent */
  28.         waitpid(pid, &exitcode, 0);
  29.         exit(0);
  30.     }
  31.  
  32.     /*
  33.      * here is the child 
  34.      */
  35.  
  36.     printf(" in the child\n");
  37.  
  38.     pid1 = fork();
  39.  
  40.     if (pid1 != 0) {    /* parent */
  41.         pid2 = getpid();
  42.         printf(" in the first child (debugger parent) %d\n", pid2);
  43.  
  44.         exec_debugger(argv[0], pid2);
  45.  
  46.         pause();
  47.  
  48.         printf("starting the loop\n");
  49.         for (i=1; i < 100; i++) {
  50.             printf("I is %d\n",i);
  51.         }
  52.         exit(1);
  53.     }
  54. }
  55.  
  56. exec_debugger(char *proc, int pid)
  57. {
  58.     char pidstr[20];
  59.  
  60.     sprintf(pidstr,"%d",pid);
  61.     printf("starting the debugger %s\n", pidstr);
  62.  
  63.     if (fork() == 0) {
  64.         execlp("/usr/bin/X11/hpterm", "/usr/bin/X11/hpterm", "-display",
  65.             "local:0", "-e", "/usr/bin/xdb", "-P", pidstr, proc,
  66.             NULL);
  67.         exit(2);
  68.     }
  69. }
  70.