【发布时间】:2013-03-23 10:51:27
【问题描述】:
我在 linux 中玩 ptrace。我正在尝试使用 /proc/pid/mem 接口编写被跟踪进程的内存。
我用来完成这项任务的功能是:
void write_proc(pid_t child, unsigned long int addr) {
char mem_file_name[100];
char buf[10]="hope";
int mem_fd;
memset( (void*)mem_file_name, 0, 100);
memset( (void *)buf, 0, 10);
sprintf(mem_file_name, "/proc/%d/mem", child);
mem_fd = open(mem_file_name, O_RDONLY);
lseek(mem_fd, addr , SEEK_SET);
if (write(mem_fd, buf, 5) < 0 )
perror("Writing");
return;
}
但我总是收到错误消息:Writing: Bad file descriptor。
是否可以使用这种方法编写被跟踪的进程?
【问题讨论】:
-
你为什么要问?
ptrace的用例是什么?
标签: linux linux-kernel linux-device-driver