#include #include #include #include #include #include void traced_process(void) { if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) exit(1); kill(getpid(), SIGCONT); if (fork()) { sleep(2); /* printf("parent: *sync=%d\n", *(unsigned char*)sync); */ } else { printf("child is alive (*sync=%d)\n", *(unsigned char*)sync); sleep(1); printf("child: *sync=%d\n", *(unsigned char*)sync); } exit(0); } int main(void) { pid_t pid; int status; int i=0; pid = fork(); if (!pid) traced_process(); while(1) { if (wait(&status)==-1) { break; } printf("ptrace(PTRACE_POKETEXT, %d, sync, %d)...\n", pid, ++i); ptrace(PTRACE_POKETEXT, pid, sync, i); ptrace(PTRACE_SYSCALL, pid, 0, 0); } exit(0); }