gh-liu / myNote

0 stars 0 forks source link

`/proc` of `linux` #17

Open gh-liu opened 3 months ago

gh-liu commented 3 months ago

/proc of linux

/proc 文件系统是一种伪文件系统(不对应真实的磁盘存储,而是内存中的一部分),为内核数据结构提供了一个接口 /proc 文件系统中的大多数文件是只读的(提供关于系统和内核的信息),但有些文件是可写的,允许更改内核变量(调优和实时控制内核行为)

man 5 proc

获取进程的信息/proc/[pid]

/proc/self 访问当前进程的信息

  1. cmdline: Command-line arguments delimited by \0
  2. cwd: Symbolic link to current working directory
  3. environ: Environment list NAME=value pairs, delimited by \0
  4. exe: Symbolic link to file being executed
  5. fd: Directory containing symbolic links to files opened by this process
  6. maps: Memory mappings
  7. mem: Process virtual memory (must lseek() to valid offset before I/O)
  8. mounts: Mount points for this process
  9. root: Symbolic link to root directory
  10. status: Various information (e.g., process IDs, credentials, memory usage, signals)
  11. task: Contains one subdirectory for each thread in process (Linux 2.6)

获取线程的信息/proc/[tid]

/proc/thread-self 访问当前线程的信息

系统级别的信息

/proc下还有许多文件和文件夹暴露了系统级别的信息

  1. /proc: Various system information
  2. /proc/net: Status information about networking and sockets
  3. /proc/sys/fs: Settings related to file systems
  4. /proc/sys/kernel: Various general kernel settings
  5. /proc/sys/net: Networking and sockets settings
  6. /proc/sys/vm: Memory-management settings
  7. /proc/sysvipc: Information about System V IPC objects