Proc is a virtual file system, which is mounted on the /proc directory in Linux systems. Proc has multiple functions, including users can access kernel information or use it for troubleshooting. One of the very useful functions and the more special function of Linux is to access process information in the form of text streams. Many Linux commands (such as ps, toPpstree, etc.) need to use this file system information. In the /proc file system, each process has a corresponding folder: /proc/pid, in which information about the process will be displayed
cmdline
/proc/[pid]/cmdline
It is a read-only file that contains the complete command line information of the process. If the process is a zombie
process, then this file has no content.
comm
/proc/[pid]/comm
Is a read-only file containing the command name of the process.
cwd
/proc/[pid]/cwd
It is a symbolic link to the current working directory of the process.
about
/proc/[pid]/environ
Display the environment variables of the process.
exe
/proc/[pid]/exe
Symbolic link for the actual running program.
fd
/proc/[pid]/fd
Is a directory that contains the status of files opened by the process.
Each item in the directory is a symbolic link that points to an open file, and the number represents a file descriptor.
latency
/proc/[pid]/latency
Show which codes cause the larger delay (to use this feature
, you need to execute " echo 1 > /proc/sys/kernel/latencytop
"). Examples are as follows:
# cat /proc/2948/latency
Latency Top version : v0.1
30667 10650491 4891 poll_schedule_timeout do_sys_poll SyS_poll system_call_fastpath 0x7f636573dc1d
8 105 44 futex_wait_queue_me futex_wait do_futex SyS_futex system_call_fastpath 0x7f6365a167bc
The first three numbers in each line are the number of executions of the following code, the total execution delay time (in microseconds) and the longest execution delay time (in microseconds), followed by the complete call stack of the code.
limits
/proc/[pid]/limits
Display the resource limit of the current process. Examples are as follows:
# cat /proc/2948/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 6409 6409 processes
Max open files 1024 4096 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 6409 6409 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
Soft Limit
Represents kernel
the value set to the resource, Hard Limit
represents Soft Limit
the upper limit, and Units
is the measurement unit
maps
/proc/[pid]/maps
Display the memory area mapping information of the process. Examples are as follows:
# cat /proc/2948/maps
......
address perms offset dev inode pathname
7f4a2e2ad000-7f4a2e2ae000 rw-p 00006000 08:14 6505977 /usr/lib64/sasl2/libsasldb.so.3.0.0
7f4a2e2ae000-7f4a2e2af000 ---p 00000000 00:00 0
7f4a2e2af000-7f4a2eaaf000 rw-p 00000000 00:00 0 [stack:94671]
7f4a2eaaf000-7f4a2eab0000 ---p 00000000 00:00 0
7f4a2eab0000-7f4a2f2b0000 rw-p 00000000 00:00 0 [stack:94670]
......
7f4a434d0000-7f4a434d5000 rw-p 0006e000 08:14 4292988 /usr/sbin/libvirtd
7f4a4520a000-7f4a452f7000 rw-p 00000000 00:00 0 [heap]
7ffd1a7e4000-7ffd1a805000 rw-p 00000000 00:00 0 [stack]
7ffd1a820000-7ffd1a821000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
One thing to note is [stack:<tid>]
the stack information of the thread, which corresponds to the /proc/[pid]/task/[tid]/
path.
root
/proc/[pid]/root
It is a symbolic link to the root directory of the process.
stack
/proc/[pid]/stack
Display the kernel call stack information of the current process CONFIG_STACKTRACE
. This file will only be generated when the compile option is turned on when the kernel is compiled . Examples are as follows:
# cat /proc/2948/stack
[<ffffffff80168375>] poll_schedule_timeout+0x45/0x60
[<ffffffff8016994d>] do_sys_poll+0x49d/0x550
[<ffffffff80169abd>] SyS_poll+0x5d/0xf0
[<ffffffff804c16e7>] system_call_fastpath+0x16/0x1b
[<00007f4a41ff2c1d>] 0x7f4a41ff2c1d
[<ffffffffffffffff>] 0xffffffffffffffff
statm
/proc/[pid]/statm
Display the statistics of the memory size occupied by the process, including seven values, the unit of measurement is page
(the page
size can be getconf PAGESIZE
obtained through ). Examples are as follows:
# cat /proc/2948/statm
72362 12945 4876 569 0 24665 0
The meaning of each value:
a) the total memory occupied by the process;
b) the physical memory occupied by the process at the current moment;
c) the memory shared with other processes;
d) the code segment of the process;
e) the shared library (from 2.6
version onwards, this value Is 0
);
f) the stack of the process;
g) dirty pages
(since 2.6
version, this value is 0
).
syscall
/proc/[pid]/syscall
Displays the system calls being executed by the current process. Examples are as follows:
# cat /proc/2948/syscall
7 0x7f4a452cbe70 0xb 0x1388 0xffffffffffdff000 0x7f4a4274a750 0x0 0x7ffd1a8033f0 0x7f4a41ff2c1d
The first value is the system call number ( 7
representative poll
), followed 6
by the parameter value of the system call (located in the register), and the last two values are the values of the stack pointer and the instruction counter in turn. If the current process is blocked, but the blocking function is not a system call, the value of the system call number is -1
followed by the value of the stack pointer and instruction counter. If the process is not blocked, this file has only a running
string of " ".
CONFIG_HAVE_ARCH_TRACEHOOK
This file will be generated when the compile option is turned on when the kernel is compiled .
wchan
/proc/[pid]/wchan
When the process is displayed sleep
, the kernel
currently running function.