Linux的命名空间
2014-01-28 10:40
381 查看
1. 为什么提供命名空间
命名空间是一种轻量级的虚拟化手段。传统的虚拟化软件,是虚拟化多个不同的操作系统,对共享资源的限制很大。
通过提供命名空间,可以让进程与进程之间,用户与用户之间彼此看不到对方。
命名空间,相当于容器。
命名空间,本质上建立了系统的不同视图。
chroot是一种简单的命名空间,仅限于将进程限制在文件系统的某一部分。
2. 创建命名空间的方式
1). fork/clone创建新进程时,可以设置选项,使新进程与父进程共享命名空间,还是新进程创建一个独立的命名空间。2). unshare系统调用,可以将进程的某些部分从父进程分离,其中也包括命名空间。
3. 实现:
struct task_struct {
......
/* namespaces */
struct nsproxy *nsproxy;
......
}
/*
* A structure to contain pointers to all per-process
* namespaces - fs (mount), uts, network, sysvipc, etc.
*
* 'count' is the number of tasks holding a reference.
* The count for each namespace, then, will be the number
* of nsproxies pointing to it, not the number of tasks.
*
* The nsproxy is shared by tasks which share all namespaces.
* As soon as a single namespace is cloned or unshared, the
* nsproxy is copied.
*/
struct nsproxy {
atomic_t count;
struct uts_namespace *uts_ns;
struct ipc_namespace *ipc_ns;
struct mnt_namespace *mnt_ns;
struct pid_namespace *pid_ns;
struct net *net_ns;
};
每个进程都有一个指针指向nsproxy结构体,多个进程可能共享一个nsproxy结构体,比如父子进程。
一个nsproxy代表一整套的命名空间实现,其中包含了几个子系统的命名空间:
UTS(UNIX Timesharing System),包含了运行内核的名称,版本,底层体系结构的信息;
IPC,包含了所有与进程间通信有关的信息;
MNT,包含了文件系统的视图;
PID,就是进程ID;
USER,就是用户;
NET,与网络相关。
各个子系统对于命名空间的实现与应用都各不相同。
相关文章推荐
- 了解Linux 命名空间
- Linux的命名空间详解--Linux进程的管理与调度(二)
- 介绍 Linux 的命名空间
- linux 网络命名空间 Network namespaces
- 第十三章 网络命名空间(内核源码实现)--基于Linux3.10
- Linux 命名空间
- Docker核心实现技术 (命名空间 & 控制组 & 联合文件系统 & Linux网络虚拟化支持)
- 『中级篇』 Linux网络命名空间(25)
- Linux课堂笔记 | 进程2——命名空间
- linux命名空间
- Linux的命名空间详解--Linux进程的管理与调度(二)【转】
- C++中的hash_map——Linux下g++和Windows下VC++下头文件,命名空间
- Linux 网络命名空间
- C++中的hash_map__Linux下g++和Windows下VC++下头文件,命名空间
- linux命名空间
- linux 容器(LXC) 第3章 命名空间(namespace) 简介
- Linux的命名空间详解--Linux进程的管理与调度(二)
- Linux进程的管理与调度(二)-- Linux的命名空间详解
- C++ 中的命名空间 namespace
- 实现Windows Server 2003 R2 DFS(3)部署命名空间