Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 从进程获取进程信息_C_Linux_Linux Kernel - Fatal编程技术网

C 从进程获取进程信息

C 从进程获取进程信息,c,linux,linux-kernel,C,Linux,Linux Kernel,我需要制作一个内核模块来显示proc目录中的一些基本进程信息。例如,获取proc中的所有进程ID并将它们存储在一个数组中。我在上检查了“proc_fs.h”头文件 但它似乎不包含任何获取此类数据的函数。如果我在这件事上错了,请纠正我 任何人都可以提供有帮助的任何此类头文件的名称或指向任何此类资源的链接。以下是程序中的一些基本和详细信息。您可以发出>sudocat/proc/{file}将信息输出到grep /proc/cpuinfo Information about the processor

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

但它似乎不包含任何获取此类数据的函数。如果我在这件事上错了,请纠正我


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

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

/proc/cpuinfo
Information about the processor, such as its type, make, model, and performance.

/proc/[pid]/cmdline
This 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.

/proc/[pid]/cwd
This is a link to the current working directory of the process.

/proc/[pid]/environ
This file contains the environment for the process. The entries are separated by null characters, and there may be a null character at the end.

/proc/[pid]/exe
The exe file is a symbolic link containing the actual path name of the executed command. The exe symbolic link can be dereferenced normally – 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].

/proc/[pid]/fd
This 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.

/proc/[pid]/maps
A file containing the currently mapped memory regions and their access permissions.

/proc/[pid]/mem
The mem file provides a means to access the process memory pages, using open, fseek and read commands.

/proc/[pid]/root
This is a link to the root directory which is seen by the process. This root directory is usually “/”, but it can be changed by the chroot command.

/proc/[pid]/stat
This 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.

/proc/devices
List of device drivers configured into the currently running kernel.

/proc/dma
Shows which DMA channels are being used at the moment.

[root@devops ~]# cat /proc/dma
4: cascade

/proc/filesystems
Filesystems configured into the kernel.

[root@devops ~]# cat /proc/filesystems
nodev sysfs
nodev rootfs
nodev bdev
nodev proc
nodev cgroup
nodev cpuset
nodev tmpfs
nodev devtmpfs
nodev binfmt_misc
nodev debugfs
nodev securityfs
nodev sockfs
nodev usbfs
nodev pipefs
nodev anon_inodefs
nodev inotifyfs
nodev devpts
nodev ramfs
nodev hugetlbfs
iso9660
nodev pstore
nodev mqueue
ext3
nodev xenfs

/proc/interrupts
Shows which interrupts are in use, and how many of each there have been.

/proc/ioports
Which I/O ports are in use at the moment.

[root@devops ~]# cat /proc/ioports
0000-0cf7 : PCI Bus 0000:00
0000-001f : dma1
0020-0021 : pic1
0040-0043 : timer0
0050-0053 : timer1
0060-0060 : keyboard
0064-0064 : keyboard
0070-0071 : rtc0
0080-008f : dma page reg
00a0-00a1 : pic2
00c0-00df : dma2

/proc/kcore
An 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.)

/proc/kmsg
Messages output by the kernel. These are also routed to syslog.

/proc/ksyms
Symbol table for the kernel.

/proc/loadavg
The `load average’ of the system; three meaningless indicators of how much work the system has to do at the moment.

/proc/meminfo
Information about memory usage, both physical and swap.

[root@devops ~]# cat /proc/meminfo
MemTotal: 500832 kB
MemFree: 116376 kB
Buffers: 1964 kB
Cached: 38772 kB
SwapCached: 0 kB
Active: 157548 kB
Inactive: 187552 kB
Active(anon): 149852 kB
Inactive(anon): 154960 kB
Active(file): 7696 kB
Inactive(file): 32592 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 96 kB
Writeback: 0 kB
AnonPages: 304388 kB
Mapped: 11180 kB
Shmem: 448 kB
Slab: 25164 kB
SReclaimable: 5872 kB
SUnreclaim: 19292 kB
KernelStack: 1040 kB
PageTables: 4028 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 250416 kB

....

/proc/modules
Which kernel modules are loaded at the moment.

[root@devops ~]# cat /proc/modules
ipv6 322541 40 - Live 0xffffffffa0112000
xenfs 6087 1 - Live 0xffffffffa010b000
dm_mod 81692 0 - Live 0xffffffffa00eb000
xen_netfront 18905 0 - Live 0xffffffffa00da000
i2c_piix4 12608 0 - Live 0xffffffffa00d1000
i2c_core 31276 1 i2c_piix4, Live 0xffffffffa00c1000
sg 30124 0 - Live 0xffffffffa00b2000
ext3 240636 2 - Live 0xffffffffa0064000
jbd 80433 1 ext3, Live 0xffffffffa0045000
mbcache 8144 1 ext3, Live 0xffffffffa003d000
sr_mod 16228 0 - Live 0xffffffffa0033000
cdrom 39803 1 sr_mod, Live 0xffffffffa0022000

/proc/net
Status information about network protocols.

/proc/self
A 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.

/proc/stat
Various statistics about the system, such as the number o

/proc/uptime
The time the system has been up.

/proc/version
The kernel version.

谢谢,但我知道这些。但是有没有一种方法,任何头文件都可以帮助我从我的内核模块中获取这些信息,这样我就可以对这些信息进行处理。你可以使用/sbin/modinfo,例如,/sbin/modinfo ide cd floppy我想anubhav需要一个C函数来获取这些信息,不是命令行程序Yes@spiffman我想知道是否有任何头文件提供函数来提取有关proc文件夹内容的信息。因此,如果您已经在内核级别运行了代码,那么您就可以访问某些结构。为什么需要/proc?为什么需要内核模块<代码>/proc显然可从用户模式获得。如果您在内核模块中,那么您可能应该使用原始信息,而不是解析
/proc
中的内容。