一些/proc和/dev问题 [英] A few /proc and /dev questions

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

问题描述

(1)/proc是否始终存在于所有linux系统上,还是某个地方的选项(例如内核编译,引导等)?

(1) Is /proc always present on all linux systems or is it an option somewhere (e.g. kernel compile, boot, etc)?

(2)是什么决定/proc中存在哪些子目录?这些是始终相同还是由用户空间程序(大概以root用户身份运行)可配置和/或可创建的?

(2) What determines what sub-directories are present in /proc? Are these always the same or are they configurable and/or creatable by user-space programs (presumably run as root)?

(3)我注意到/dev/shm存在于我的系统中,而无需挂载它,也不存在于/etc/fstab中.这是自动的还是有创造力的?相反,我必须挂载/dev/mqueue.这不应该也自动安装吗?

(3) I noticed that /dev/shm was present on my system without having to mount it nor is it present in /etc/fstab. Is this automatic or does something create it? Conversely, I have to mount /dev/mqueue. Shouldn't this be auto mounted as well?

(4)以编程方式确定是否已安装设备或目录的正常/最佳方法是什么?应该只是寻找开放性错误,还是对此进行API调用.

(4) What is the normal/best way to determine programatically if a device or directory is mounted? Should one just look for open errors or is there an API call for this.

谢谢.

推荐答案

  1. /proc通常由初始化脚本安装,如下所示:

  1. /proc is typically mounted by the init scripts, like this:


mount none /proc -t proc

如果不这样做,您将看不到/proc的预期内容(但是您还将拥有一个不兼容POSIX的系统).

If this is not done, you will not see the expected contents of /proc (but then you will also have a non-POSIX-compliant system).


$ grep proc /proc/filesystems
nodev   proc

proc是内核导出的虚拟文件系统.它的内容完全*由内核和加载的模块确定,这些模块可以注册以添加其他条目.

proc is a virtual filesystem exported by the kernel. Its contents are entirely* determined by the kernel and loaded modules which can register to add additional entries.

*除了/proc中有一些子目录通常会被其他虚拟文件系统重载,例如:
mount none /proc/bus/usb -t usbfs -o devmode=0664,devgid=plugdev
mount none /proc/sys/fs/binfmt_misc -t binfmt_misc
mount none /proc/fs/nfsd -t nfsd

* Except that there are some subdirectories in /proc which are commonly overmounted with other virtual filesystems, for example:
mount none /proc/bus/usb -t usbfs -o devmode=0664,devgid=plugdev
mount none /proc/sys/fs/binfmt_misc -t binfmt_misc
mount none /proc/fs/nfsd -t nfsd

检查您的初始化脚本. /sbin/init查看/etc/inittab以确定要运行的内容(通常是/sbin/rc或类似内容,然后通过/etc/rcS.d/*等),并且您的发行版很有可能会在initramfs中进行初步设置以及.

Check your init scripts. /sbin/init looks at /etc/inittab to determine what to run, which is often /sbin/rc or similar, which then goes through /etc/rcS.d/* etc., and there is also a good possibility that your distribution will do preliminary setup in the initramfs as well.

视情况而定.

您可以读取mount命令的输出,/proc/mounts文件或更新的内核上的/proc/self/mounts//proc/self/mountinfo文件,以确定当前安装的内容.

You can read the output of the mount command, or the /proc/mounts file, or the /proc/self/mounts / /proc/self/mountinfo files on newer kernels, to determine what is currently mounted.

您可以将目录statst_dev与目录的父目录进行比较;如果不同,则该目录为挂载点.

You can compare the st_dev of stat of a directory to its parent; if different, the directory is a mountpoint.

除非您正在编写要在非标准系统上运行或在系统安装之前启动的代码,否则可以假定已安装/dev/proc/sys等.

Unless you are writing code to be running on a non-standard system or at boot before the system has been set up, you may assume that /dev, /proc, /sys, etc. are mounted.

这篇关于一些/proc和/dev问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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