从proc获取进程信息

anu*_*hav 4 c linux linux-kernel

我需要制作一个内核模块来显示 proc 目录中的一些基本进程信息。例如。获取 proc 中的所有进程 ID 并将它们存储在数组中。我在此链接上检查了“proc_fs.h”头文件

但它似乎不包含任何获取此类数据的功能。如果我对此有误,请纠正我。

任何人都可以提供任何此类有用的头文件的名称或任何此类资源的链接。

uni*_*iah 9

以下是过程中的一些基本和详细信息。您可以发出 > sudo cat /proc/{file} 将信息输出到 grep。

\n\n
/proc/cpuinfo\nInformation about the processor, such as its type, make, model, and performance.\n\n/proc/[pid]/cmdline\nThis holds the complete command line for the process, unless the whole process has been swapped out, or unless the process is a zombie. In either of these later cases, there is nothing in this file: i.e. a read on this file will return 0 characters. The command line arguments appear in this file as a set of null-separated strings, with a further null byte after the last string.\n\n/proc/[pid]/cwd\nThis is a link to the current working directory of the process.\n\n/proc/[pid]/environ\nThis file contains the environment for the process. The entries are separated by null characters, and there may be a null character at the end.\n\n/proc/[pid]/exe\nThe exe file is a symbolic link containing the actual path name of the executed command. The exe symbolic link can be dereferenced normally \xe2\x80\x93 attempting to open exe will open the executable. You can even type /proc/[pid]/exe to run another copy of the same process as [pid].\n\n/proc/[pid]/fd\nThis is a subdirectory containing one entry for each file which the process has opened, named by its file descriptor, and which is a symbolic link to the actual file (as the exe entry does). Thus, 0 is standard input, 1 standard output, 2 standard error, etc.\n\n/proc/[pid]/maps\nA file containing the currently mapped memory regions and their access permissions.\n\n/proc/[pid]/mem\nThe mem file provides a means to access the process memory pages, using open, fseek and read commands.\n\n/proc/[pid]/root\nThis is a link to the root directory which is seen by the process. This root directory is usually \xe2\x80\x9c/\xe2\x80\x9d, but it can be changed by the chroot command.\n\n/proc/[pid]/stat\nThis file provides status information about the process. This is used by the Process Show utility. It is defined in fs/proc/array.c source file and may differ from one distribution to another.\n\n/proc/devices\nList of device drivers configured into the currently running kernel.\n\n/proc/dma\nShows which DMA channels are being used at the moment.\n\n[root@devops ~]# cat /proc/dma\n4: cascade\n\n/proc/filesystems\nFilesystems configured into the kernel.\n\n[root@devops ~]# cat /proc/filesystems\nnodev sysfs\nnodev rootfs\nnodev bdev\nnodev proc\nnodev cgroup\nnodev cpuset\nnodev tmpfs\nnodev devtmpfs\nnodev binfmt_misc\nnodev debugfs\nnodev securityfs\nnodev sockfs\nnodev usbfs\nnodev pipefs\nnodev anon_inodefs\nnodev inotifyfs\nnodev devpts\nnodev ramfs\nnodev hugetlbfs\niso9660\nnodev pstore\nnodev mqueue\next3\nnodev xenfs\n\n/proc/interrupts\nShows which interrupts are in use, and how many of each there have been.\n\n/proc/ioports\nWhich I/O ports are in use at the moment.\n\n[root@devops ~]# cat /proc/ioports\n0000-0cf7 : PCI Bus 0000:00\n0000-001f : dma1\n0020-0021 : pic1\n0040-0043 : timer0\n0050-0053 : timer1\n0060-0060 : keyboard\n0064-0064 : keyboard\n0070-0071 : rtc0\n0080-008f : dma page reg\n00a0-00a1 : pic2\n00c0-00df : dma2\n\n/proc/kcore\nAn image of the physical memory of the system. This is exactly the same size as your physical memory, but does not really take up that much memory; it is generated on the fly as programs access it. (Remember: unless you copy it elsewhere, nothing under /proc takes up any disk space at all.)\n\n/proc/kmsg\nMessages output by the kernel. These are also routed to syslog.\n\n/proc/ksyms\nSymbol table for the kernel.\n\n/proc/loadavg\nThe `load average\xe2\x80\x99 of the system; three meaningless indicators of how much work the system has to do at the moment.\n\n/proc/meminfo\nInformation about memory usage, both physical and swap.\n\n[root@devops ~]# cat /proc/meminfo\nMemTotal: 500832 kB\nMemFree: 116376 kB\nBuffers: 1964 kB\nCached: 38772 kB\nSwapCached: 0 kB\nActive: 157548 kB\nInactive: 187552 kB\nActive(anon): 149852 kB\nInactive(anon): 154960 kB\nActive(file): 7696 kB\nInactive(file): 32592 kB\nUnevictable: 0 kB\nMlocked: 0 kB\nSwapTotal: 0 kB\nSwapFree: 0 kB\nDirty: 96 kB\nWriteback: 0 kB\nAnonPages: 304388 kB\nMapped: 11180 kB\nShmem: 448 kB\nSlab: 25164 kB\nSReclaimable: 5872 kB\nSUnreclaim: 19292 kB\nKernelStack: 1040 kB\nPageTables: 4028 kB\nNFS_Unstable: 0 kB\nBounce: 0 kB\nWritebackTmp: 0 kB\nCommitLimit: 250416 kB\n\n....\n\n/proc/modules\nWhich kernel modules are loaded at the moment.\n\n[root@devops ~]# cat /proc/modules\nipv6 322541 40 - Live 0xffffffffa0112000\nxenfs 6087 1 - Live 0xffffffffa010b000\ndm_mod 81692 0 - Live 0xffffffffa00eb000\nxen_netfront 18905 0 - Live 0xffffffffa00da000\ni2c_piix4 12608 0 - Live 0xffffffffa00d1000\ni2c_core 31276 1 i2c_piix4, Live 0xffffffffa00c1000\nsg 30124 0 - Live 0xffffffffa00b2000\next3 240636 2 - Live 0xffffffffa0064000\njbd 80433 1 ext3, Live 0xffffffffa0045000\nmbcache 8144 1 ext3, Live 0xffffffffa003d000\nsr_mod 16228 0 - Live 0xffffffffa0033000\ncdrom 39803 1 sr_mod, Live 0xffffffffa0022000\n\n/proc/net\nStatus information about network protocols.\n\n/proc/self\nA symbolic link to the process directory of the program that is looking at /proc. When two processes look at /proc, they get different links. This is mainly a convenience to make it easier for programs to get at their process directory.\n\n/proc/stat\nVarious statistics about the system, such as the number o\n\n/proc/uptime\nThe time the system has been up.\n\n/proc/version\nThe kernel version.\n
Run Code Online (Sandbox Code Playgroud)\n