设置 write 线程
章节大纲
-
write 线程的任务是将内存中的字符串 "222222" 替换为 "******"。 由于映射内存是 COW 类型,仅通过该线程只能修改映射内存的副本内容,无法对底层的 /zzz 文件产生任何更改。
void *writeThread(void *arg) { char *content= "******"; off_t offset = (off_t) arg; int f=open("/proc/self/mem", O_RDWR); while(1) { // 将文件指针移动到相应位置。 lseek(f, offset, SEEK_SET); // 向内存写入。 write(f, content, strlen(content)); } }