一步一步粗谈linux文件系统(五)----关于fork,文件系统在各个进程中
来源:互联网 发布:php网站源代码 编辑:程序博客网 时间:2024/06/04 19:41
关于fork,我们都知道fork出新的进程,会复制旧进程的所有资源,且堆栈、数据不共享。所以关于文件系统,要是不共享,会出现怎么样的情况呢?就是说各个进程都有自己的文件系统copy,那种感觉不敢想象,所以他们一定是资源共享的,一定是同步的。
在fork新进程的操作中,其中
static structtask_struct *copy_process(unsigned long clone_flags,
unsignedlong stack_start,
structpt_regs *regs,
unsignedlong stack_size,
int__user *parent_tidptr,
int__user *child_tidptr,
intpid)
中调用了
if ((retval =copy_fs(clone_flags,p))) //文件下系统copy
gotobad_fork_cleanup_files;
最终调用了
static inline struct fs_struct *__copy_fs_struct(struct fs_struct *old){struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);//fs分配一块内存区域/* We don't need to lock fs - think why ;-) */if (fs) {atomic_set(&fs->count, 1);rwlock_init(&fs->lock);fs->umask = old->umask;read_lock(&old->lock);fs->rootmnt = mntget(old->rootmnt);fs->root = dget(old->root);fs->pwdmnt = mntget(old->pwdmnt);fs->pwd = dget(old->pwd);if (old->altroot) {fs->altrootmnt = mntget(old->altrootmnt);fs->altroot = dget(old->altroot);} else {fs->altrootmnt = NULL;fs->altroot = NULL;}read_unlock(&old->lock);}return fs;}
亮点在哪?指针!struct fs_struct *fs;你没有看错,就是这个指针,再结合下面的代码,可以得出,fork出来新的文件系统指针指向于旧的那一块指向的。那意味着,后面不管是那个进程的task->fs其实都是进程0创建出来的fs,即前面一篇中所提到的rootfs,所以各个进程间的文件系统是资源共享的,同步的。
- 一步一步粗谈linux文件系统(五)----关于fork,文件系统在各个进程中
- 一步一步粗谈linux文件系统(二)---------文件系统初始化
- 一步一步粗谈linux文件系统(一)----start_kernel
- 一步一步粗谈linux文件系统(三)----超级块(superblock)
- 一步一步粗谈linux文件系统(四)----挂载VFS
- 一步一步粗谈linux文件系统(七)----sysfs概述
- 一步一步粗谈linux文件系统(八)---- subsystem_register
- 一步一步粗谈linux文件系统(九)---- device_register
- 一步一步粗谈linux文件系统(四)----挂载VFS
- 一步一步粗谈linux文件系统(六)----ramfs的读、写
- 在Linux文件系统中跳转
- Linux体系结构(五): 文件系统
- 一步一步学习Linux(2):Linux常用根文件系统
- Linux 根文件系统中各个主要目录存放的内容
- Linux中关于fork()复制进程
- Linux 学习笔记(五)文件系统
- Linux命令之文件系统(五)
- 构建Linux根文件系统(五)
- 用Forms编写的数字时钟
- 读取HDFS 系统中数据
- Unicode环境下使用Gsoap的总结
- javax.faces.FacesException: java.lang.LinkageError解决办法
- 什么是集成产品开发(IPD),如何在公司内推行实施?
- 一步一步粗谈linux文件系统(五)----关于fork,文件系统在各个进程中
- 破圈法求最小生成树 代码
- 《民族大迁徙》的第一章节选
- WampServer篇——WampServer2.0i 下配置多用户
- 定义属性为 null 与 直接写分号有什么区别
- 2012.12.17
- DBMS_OUTPUT.PUT_LINE的輸出內容在屏幕上显示
- 关于Android 的一些基本概念
- 绕开AS3安全沙箱,跨域加载SWF