Chinaunix

标题: 为啥PTRACE_DETACH后进程状态还是traced? [打印本页]

作者: rootclown    时间: 2007-01-05 13:32
标题: 为啥PTRACE_DETACH后进程状态还是traced?
用ptrace  attach一个进程后,向其写入一段代码,然后detach
为啥PTRACE_DETACH后进程状态还是traced?


  1. TTY1
  2. [root@localhost tmp]# gcc a.c -o target -ldl
  3. [root@localhost tmp]# ./target
  4. 80483c8
  5. hhhh
  6. hhhh
  7. hhhh
  8. hhhh

  9. [1]+  Stopped                 ./target
  10. [root@localhost tmp]#
复制代码



  1. TTY2
  2. [root@localhost prog]# ps a
  3.   PID TTY      STAT   TIME COMMAND
  4. 2629 tty2     Ss+    0:00 /sbin/mingetty tty2
  5. 2630 tty3     Ss+    0:00 /sbin/mingetty tty3
  6. 2631 tty4     Ss+    0:00 /sbin/mingetty tty4
  7. 2632 tty5     Ss+    0:00 /sbin/mingetty tty5
  8. 2633 tty6     Ss+    0:00 /sbin/mingetty tty6
  9. 2628 tty1     Ts+    0:00 /sbin/mingetty tty1
  10. 1577 pts/2    Ss+    0:00 -bash
  11. 11045 pts/1    Ss     0:00 -bash
  12. 11718 pts/3    Ss     0:00 -bash
  13. 12397 pts/4    Ss+    0:00 -bash
  14. 13234 pts/1    S+     0:00 ./target        ## here
  15. 13236 pts/3    R+     0:00 ps a
  16. [root@localhost prog]# ./a.out 13234

  17. b16050
  18. 80489ec

  19. eip : a027a2
  20. [root@localhost prog]# ps a
  21.   PID TTY      STAT   TIME COMMAND
  22. 2629 tty2     Ss+    0:00 /sbin/mingetty tty2
  23. 2630 tty3     Ss+    0:00 /sbin/mingetty tty3
  24. 2631 tty4     Ss+    0:00 /sbin/mingetty tty4
  25. 2632 tty5     Ss+    0:00 /sbin/mingetty tty5
  26. 2633 tty6     Ss+    0:00 /sbin/mingetty tty6
  27. 2628 tty1     Ts+    0:00 /sbin/mingetty tty1
  28. 1577 pts/2    Ss+    0:00 -bash
  29. 11045 pts/1    Ss+    0:00 -bash
  30. 11718 pts/3    Ss     0:00 -bash
  31. 12397 pts/4    Ss+    0:00 -bash
  32. 13234 pts/1    T      0:00 ./target       ## here
  33. 13238 pts/3    R+     0:00 ps a
复制代码


注入的部分代码如下:

  1.         __asm__(
  2.                 /// sys getpid
  3.                 "movl $20, %eax\n\t"
  4.                 "int $0x80\n\t"

  5.                 /// kill()
  6.                 "movl %eax, %ebx\n\t"
  7.                 "movl $37, %eax\n\t"
  8.                 "movl $19, %ecx\n\t"
  9.                 "int $0x80\n\t"

复制代码

[ 本帖最后由 rootclown 于 2007-1-5 13:57 编辑 ]
作者: Benson_linux    时间: 2007-04-10 10:03
把这个帖子顶起来,希望LZ看到,把内容在补全一些,你问题描述的不清楚啊。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2