重定向文件访问 [英] Redirect file access

查看:160
本文介绍了重定向文件访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来监控和重定向线程或进程的文件访问?

Is there a way to monitor and redirect file access of a thread or process?

例如一个线程想读/etc/mysql/my.cnf,我想改变访问到〜/ my.cnf中,或者如果我运行触摸/etc/test.config我想要的文件被重定向到〜/ somefolder的/ etc / test.config

For example a thread wants to read /etc/mysql/my.cnf and I want to change the access to ~/my.cnf or if I run touch /etc/test.config I want the file to be redirected to ~/somefolder/etc/test.config.

我要寻找一个libary preferably为C,C ++该工程的Linux / Unix。

I am looking for a libary preferably for C, C++ which works for Linux/Unix.

在此先感谢

推荐答案

在Linux中,可以使用绑定坐骑映射目录的或文件的另一个路径,每个进程挂载命名空间做针对特定的应用程序。

In linux, you can use bind mounts to map directory or file to another path, and per-process mount namespaces to do it for specific application.

请参阅this问题。

例1:使用 PROOT

$ proot -b ~/alternate_hosts:/etc/hosts
# echo '1.2.3.4 google.com' > /etc/hosts
# resolveip google.com
# IP address of google.com is 1.2.3.4

例2:使用取消共享(1 )

$ unshare -m
# touch foo bar
# mount -o bind foo bar
# echo hello > foo
# cat bar
hello

例3:使用取消共享(2 )

请参阅这篇文章: http://glandium.org/blog/?p=217

这篇关于重定向文件访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆