home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / ultrix / 8203 < prev    next >
Encoding:
Text File  |  1992-11-10  |  2.3 KB  |  87 lines

  1. Path: sparky!uunet!spool.mu.edu!agate!asami
  2. From: asami@cs.Berkeley.EDU (Satoshi ASAMI)
  3. Newsgroups: comp.unix.ultrix
  4. Subject: ptrace(20, pid...) doesn't work
  5. Date: 10 Nov 92 02:54:07
  6. Organization: CS Div., Dept. of EECS, UC Berkeley
  7. Lines: 75
  8. Message-ID: <ASAMI.92Nov10025407@anaconda.cs.Berkeley.EDU>
  9. Reply-To: asami@snake.cs.berkeley.edu
  10. NNTP-Posting-Host: anaconda.cs.berkeley.edu
  11.  
  12. Hi netters.  I have a problem with the ptrace() system call.  The
  13. following program, which runs on an HP with little modification (the
  14. number of arguments are different), doesn't work on my DECstation5000
  15. ("uname -a" says "ULTRIX papaya.Berkeley.EDU 4.2 0 RISC").  Anyway
  16. knows what's wrong?
  17.  
  18. ===<begin program>===
  19. /* ptrace.c: ptrace test program */
  20.  
  21. #include <stdio.h>
  22. #include <signal.h>
  23. #include <sys/ptrace.h>
  24. #include <sys/types.h>
  25. #include <unistd.h>
  26. #include <errno.h>
  27. #include <string.h>
  28.  
  29. #define OK      0
  30.  
  31. int main(int argc, char **argv)
  32. {
  33.     pid_t       pid ;
  34.  
  35.     if (argc < 2)       {
  36.         fprintf(stderr, "usage: %s prog [args...]\n", argv[0]) ;
  37.         exit(1) ;
  38.     }
  39.  
  40.     if ((pid = fork()) == -1)   {
  41.         fprintf(stderr, "panic: can't fork()\n") ;
  42.         exit(2) ;
  43.     }
  44.  
  45.     if (pid == 0)       {
  46.         argv++ ;
  47.         execvp(argv[0], argv) ;
  48.         fprintf(stderr, "panic: can't exec()\n") ;
  49.         exit(3) ;
  50.     }
  51.  
  52.     sleep(10) ;
  53.  
  54.     printf("stopping child....\n") ;
  55.  
  56.     if (ptrace(20, pid, NULL, 0) == -1) {
  57.         fprintf(stderr, "ptrace 20, %d (%d): %s\n", errno, pid, strerror(errno)) ;
  58.         exit(4) ;
  59.     }
  60.  
  61.     ptrace(8, pid, NULL, 0) ;   /* terminate */
  62.  
  63.     return (OK) ;
  64. }
  65. ===<end program>===
  66.  
  67. When I compile this using cc and run it, it says
  68. ===<begin session>===
  69. % ptrace xeyes
  70. stopping child....
  71. ptrace 20, 3 (3190): No such process
  72. %
  73. ===<end session>===
  74. and ptrace terminates but xeyes continues running.
  75.  
  76. However, when I substitute ptrace(20,pid,...) with something like
  77. kill(pid, SIGSTOP), the eyes freeze as expected.  Hmmm...."No such
  78. process"....?
  79.  
  80. Thanks in advance,
  81. ===
  82.                                                    o o   Satoshi Asami
  83.   Form follows Function.                            ^
  84.                                                (asami@CS.Berkeley.EDU)
  85.   Tel: (510)643-2730 (home)       Computer Science Div., Dept. of EECS
  86.        (510)643-6228 (office)     University of California at Berkeley
  87.