linux中mqueue是什么意思

linux中mqueue是什么意思,第1张

mqueue是mail queue,即邮件消息队列。

The mail queue is a directory that stores data and controls files for mail messages that the sendmail command delivers. By default, the mail queue is /var/spool/mqueue.

mail queue 是一个目录,它为发送邮件保存数据和控制文件。默认情况下在/var/spool/mqueue。

由于Linux内核提供了PID,IPC,NS等多个Namespace,一个进程可能属于多个Namespace。为了task_struct的精简,内核引入了struct nsproxy来统一管理进程所属的Namespace,在task_struct中只需存一个指向struct nsproxy的指针就行了。struct nsproxy定义如下:struct nsproxy {atomic_t countstruct uts_namespace *uts_nsstruct ipc_namespace *ipc_nsstruct mnt_namespace *mnt_nsstruct pid_namespace *pid_nsstruct net *net_ns}从定义可以看出,nsproxy存储了一组指向各个类型Namespace的指针,为进程访问各个Namespace起了一个代理的作用。由于可能有多个进程所在的Namespace完全一样,nsproxy可以在进程间共享,count字段负责记录该结构的引用数。系统预定义了一个init_nsproxy,用作默认的nsproxy。struct nsproxy init_nsproxy = {_ns = &init_net,#endif}其中除了mnt_ns外均指向系统默认的Namespace。内核定义了一组函数来管理nsproxy:task_nsproxy用于从task_struct指针在RCU保护下获得其中的nsproxy指针。put_nsproxy用于减少一个nsproxy的引用数。get_nsproxy用于增加一个nsproxy的引用数。create_nsproxy用于分配一个新的nsproxy结构。下面我们来看系统在clone时的处理。系统调用clone是通过sys_clone实现的,而sys_clone又是通过内核函数do_fork实现的,而do_fork大部分工作又是在copy_process中做的。在copy_process中,有这样的代码:if ((retval = copy_namespaces(clone_flags, p)))goto bad_fork_cleanup_mm这里我们回过头去看copy_namespaces的代码int copy_namespaces(unsigned long flags, struct task_struct *tsk){struct nsproxy *old_ns = tsk->nsproxystruct nsproxy *new_nsint err = 0 if (!old_ns)return 0 get_nsproxy(old_ns) if (!(flags &(CLONE_NEWNS CLONE_NEWUTS CLONE_NEWIPC CLONE_NEWPID CLONE_NEWNET)))return 0 if (!capable(CAP_SYS_ADMIN)) {err = -EPERMgoto out} /* * CLONE_NEWIPC must detach from the undolist: after switching * to a new ipc namespace, the semaphore arrays from the old * namespace are unreachable. In clone parlance, CLONE_SYSVSEM * means share undolist with parent, so we must forbid using * it along with CLONE_NEWIPC. */if ((flags &CLONE_NEWIPC) &&(flags &CLONE_SYSVSEM)) {err = -EINVALgoto out} new_ns = create_new_namespaces(flags, tsk, tsk->fs)if (IS_ERR(new_ns)) {err = PTR_ERR(new_ns)goto out} tsk->nsproxy = new_ns out:put_nsproxy(old_ns)return err}该函数首先检查flags,如果没有指定任何一个需要新建Namespace的flag,直接返回0。否则,做相应的权能检查,然后调用create_new_namespaces为进程创建新的Namespace。我们再来看create_new_namespaces的代码static struct nsproxy *create_new_namespaces(unsigned long flags,struct task_struct *tsk, struct fs_struct *new_fs){struct nsproxy *new_nspint err new_nsp = create_nsproxy()if (!new_nsp)return ERR_PTR(-ENOMEM) new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs)if (IS_ERR(new_nsp->mnt_ns)) {err = PTR_ERR(new_nsp->mnt_ns)goto out_ns} new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns)if (IS_ERR(new_nsp->uts_ns)) {err = PTR_ERR(new_nsp->uts_ns)goto out_uts} new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns)if (IS_ERR(new_nsp->ipc_ns)) {err = PTR_ERR(new_nsp->ipc_ns)goto out_ipc} new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk))if (IS_ERR(new_nsp->pid_ns)) {err = PTR_ERR(new_nsp->pid_ns)goto out_pid}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/6239183.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-18
下一篇2023-03-18

发表评论

登录后才能评论

评论列表(0条)

    保存