home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!agate!asami
- From: asami@cs.Berkeley.EDU (Satoshi ASAMI)
- Newsgroups: comp.unix.ultrix
- Subject: ptrace(20, pid...) doesn't work
- Date: 10 Nov 92 02:54:07
- Organization: CS Div., Dept. of EECS, UC Berkeley
- Lines: 75
- Message-ID: <ASAMI.92Nov10025407@anaconda.cs.Berkeley.EDU>
- Reply-To: asami@snake.cs.berkeley.edu
- NNTP-Posting-Host: anaconda.cs.berkeley.edu
-
- Hi netters. I have a problem with the ptrace() system call. The
- following program, which runs on an HP with little modification (the
- number of arguments are different), doesn't work on my DECstation5000
- ("uname -a" says "ULTRIX papaya.Berkeley.EDU 4.2 0 RISC"). Anyway
- knows what's wrong?
-
- ===<begin program>===
- /* ptrace.c: ptrace test program */
-
- #include <stdio.h>
- #include <signal.h>
- #include <sys/ptrace.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <errno.h>
- #include <string.h>
-
- #define OK 0
-
- int main(int argc, char **argv)
- {
- pid_t pid ;
-
- if (argc < 2) {
- fprintf(stderr, "usage: %s prog [args...]\n", argv[0]) ;
- exit(1) ;
- }
-
- if ((pid = fork()) == -1) {
- fprintf(stderr, "panic: can't fork()\n") ;
- exit(2) ;
- }
-
- if (pid == 0) {
- argv++ ;
- execvp(argv[0], argv) ;
- fprintf(stderr, "panic: can't exec()\n") ;
- exit(3) ;
- }
-
- sleep(10) ;
-
- printf("stopping child....\n") ;
-
- if (ptrace(20, pid, NULL, 0) == -1) {
- fprintf(stderr, "ptrace 20, %d (%d): %s\n", errno, pid, strerror(errno)) ;
- exit(4) ;
- }
-
- ptrace(8, pid, NULL, 0) ; /* terminate */
-
- return (OK) ;
- }
- ===<end program>===
-
- When I compile this using cc and run it, it says
- ===<begin session>===
- % ptrace xeyes
- stopping child....
- ptrace 20, 3 (3190): No such process
- %
- ===<end session>===
- and ptrace terminates but xeyes continues running.
-
- However, when I substitute ptrace(20,pid,...) with something like
- kill(pid, SIGSTOP), the eyes freeze as expected. Hmmm...."No such
- process"....?
-
- Thanks in advance,
- ===
- o o Satoshi Asami
- Form follows Function. ^
- (asami@CS.Berkeley.EDU)
- Tel: (510)643-2730 (home) Computer Science Div., Dept. of EECS
- (510)643-6228 (office) University of California at Berkeley
-