Цитата(konshyn @ 11.11.2013, 14:10 ) | | Как узнать, сколько выделено памяти в определенный момент, |
Открывать и читать разные файлы из /proc/self/:
| Цитата | /proc/[pid]/maps A file containing the currently mapped memory regions and their access permissions. The format is: address perms offset dev inode pathname 08048000-08056000 r-xp 00000000 03:0c 64593 /usr/sbin/gpm 08056000-08058000 rw-p 0000d000 03:0c 64593 /usr/sbin/gpm 08058000-0805b000 rwxp 00000000 00:00 0 40000000-40013000 r-xp 00000000 03:0c 4165 /lib/ld-2.2.4.so 40013000-40015000 rw-p 00012000 03:0c 4165 /lib/ld-2.2.4.so 4001f000-40135000 r-xp 00000000 03:0c 45494 /lib/libc-2.2.4.so 40135000-4013e000 rw-p 00115000 03:0c 45494 /lib/libc-2.2.4.so 4013e000-40142000 rw-p 00000000 00:00 0 bffff000-c0000000 rwxp 00000000 00:00 0 where "address" is the address space in the process that it occupies, "perms" is a set of permissions: r = read w = write x = execute s = shared p = private (copy on write) "offset" is the offset into the file/whatever, "dev" is the device (major:minor), and "inode" is the inode on that device. 0 indicates that no inode is associated with the memory region, as the case would be with BSS (uninitialized data). Under Linux 2.0 there is no field giving pathname.
|
| Цитата | /proc/[pid]/smaps (since Linux 2.6.14) This file shows memory consumption for each of the process's mappings. For each of mappings there is a series of lines such as the fol- lowing: 08048000-080bc000 r-xp 00000000 03:02 13130 /bin/bash Size: 464 kB Rss: 424 kB Shared_Clean: 424 kB Shared_Dirty: 0 kB Private_Clean: 0 kB Private_Dirty: 0 kB The first of these lines shows the same information as is displayed for the mapping in /proc/[pid]/maps. The remaining lines show the size of the mapping, the amount of the mapping that is currently resident in RAM, the number of clean and dirty shared pages in the map- ping, and the number of clean and dirty private pages in the mapping. This file is only present if the CONFIG_MMU kernel configuration option is enabled.
|
Немного урезал -
| Цитата | /proc/[pid]/stat Status information about the process. This is used by ps(1). It is defined in /usr/src/linux/fs/proc/array.c. The fields, in order, with their proper scanf(3) format specifiers, are: pid %d The process ID. comm %s The filename of the executable, in parentheses. state %c One character from the string "RSDZTW" ppid %d The PID of the parent. pgrp %d The process group ID of the process. session %d The session ID of the process. tty_nr %d The controlling terminal of the process. tpgid %d The ID of the foreground process group of the controlling terminal of the process. flags %u (%lu before Linux 2.6.22) The kernel flags word of the process. minflt %lu The number of minor faults the process has made... cminflt %lu The number of minor faults that the process's waited-for children have made. majflt %lu The number of major faults the process has made ... cmajflt %lu The number of major faults that the process's waited-for children have made. utime %lu Amount of time that this process has been scheduled in user mode, stime %lu Amount of time that this process has been scheduled in kernel mode cutime %ld Amount of time that this process's waited-for children have been scheduled in user mode cstime %ld Amount of time that this process's waited-for children have been scheduled in kernel mode priority %ld For processes running a real-time scheduling policy nice %ld The nice value (see setpriority(2)), num_threads %ld Number of threads in this process (since Linux 2.6). itrealvalue %ld The time in jiffies before the next SIGALRM is sent to the process due to an interval timer. starttime %llu (was %lu before Linux 2.6) The time in jiffies the process started after system boot. vsize %lu Virtual memory size in bytes.
rss %ld Resident Set Size: number of pages the process has in real memory. This is just the pages which count towards text, data, or stack space. This does not include pages which have not been demand-loaded in, or which are swapped out. ....
|
| Цитата | /proc/[pid]/statm Provides information about memory usage, measured in pages. The columns are: size total program size (same as VmSize in /proc/[pid]/status) resident resident set size (same as VmRSS in /proc/[pid]/status) share shared pages (from shared mappings) text text (code) lib library (unused in Linux 2.6) data data + stack dt dirty pages (unused in Linux 2.6)
|
| Цитата | /proc/[pid]/status Provides much of the information in /proc/[pid]/stat and /proc/[pid]/statm in a format that's easier for humans to parse. Here's an exam- ple: $ cat /proc/$$/status Name: bash State: S (sleeping) Tgid: 3515 Pid: 3515 PPid: 3452 TracerPid: 0 Uid: 1000 1000 1000 1000 Gid: 100 100 100 100 FDSize: 256 Groups: 16 33 100 VmPeak: 9136 kB VmSize: 7896 kB VmLck: 0 kB VmHWM: 7572 kB VmRSS: 6316 kB VmData: 5224 kB VmStk: 88 kB VmExe: 572 kB VmLib: 1708 kB VmPTE: 20 kB Threads: 1 SigQ: 0/3067 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000010000 SigIgn: 0000000000384004 SigCgt: 000000004b813efb CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: ffffffffffffffff Cpus_allowed: 00000001 Cpus_allowed_list: 0 Mems_allowed: 1 Mems_allowed_list: 0 voluntary_ctxt_switches: 150 nonvoluntary_ctxt_switches: 545
The fields are as follows:
* VmPeak: Peak virtual memory size. * VmSize: Virtual memory size. * VmLck: Locked memory size. * VmHWM: Peak resident set size ("high water mark"). * VmRSS: Resident set size. * VmData, VmStk, VmExe: Size of data, stack, and text segments. * VmLib: Shared library code size. * VmPTE: Page table entries size (since Linux 2.6.10).
|
В общем смотри man 5 proc
|