├── .gitignore ├── CONTRIBUTING.md ├── README.md ├── diskstats.md ├── index.js ├── lib ├── nettable.js └── parse-addr.js ├── optional └── wifi.js ├── package.json ├── proc.txt └── test ├── cpu.js ├── custompath.js ├── disk.js ├── fds.js ├── io.js ├── meminfo.js ├── net.js ├── pid_argv.js ├── pid_cwd.js ├── pid_env.js ├── pid_stat.js ├── pid_statm.js ├── pid_status.js ├── pid_threads.js ├── tcp.js ├── udp.js └── unix.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # procfs-stats Contributing Guidelines 2 | 3 | - Always search for a related issue before starting a new issue. 4 | - Always choose a concise, helpful issue name. 5 | - Always stay on-topic. If you've got a new bug report or feature request, put it in its own issue. 6 | - Always be polite to other people. 7 | - Never post private information, such as torrent or tracker names, IP addresses, etc. 8 | 9 | Issues that break the rules may be deleted and locked without warning. 10 | 11 | ## procfs-stats is an OPEN Open Source Project 12 | 13 | Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project. 14 | 15 | ## Rules 16 | 17 | There are a few basic ground-rules for contributors: 18 | 19 | 1. **No `--force` pushes** or modifying the Git history in any way. 20 | 1. **External API changes and significant modifications** should be subject to a **pull request** to solicit feedback from other contributors. 21 | 1. Pull requests to solicit feedback are *encouraged* for any other non-trivial contribution but left to the discretion of the contributor. 22 | 1. Use a non-`master` branch for ongoing work. 23 | 1. Contributors should attempt to adhere to the prevailing code style. 24 | 1. Run `npm test` locally before submitting your PR to catch easy-to-miss style & testing issues 25 | 26 | ## Releases 27 | 28 | Declaring formal releases remains the prerogative of the project maintainer. 29 | 30 | 31 | ## notes 32 | 33 | *Thanks to [Rod Vagg](https://github.com/rvagg) and the [LevelUP](https://github.com/rvagg/node-levelup) project for coming up with this model of open source contribution.* 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | procfs-stats 2 | ============ 3 | 4 | get detailed information about running process and threads on linux machines from node. more than ps/top/iostat alone 5 | 6 | ```js 7 | 8 | var procfs = require('procfs-stats'); 9 | var ps = procfs(process.pid); 10 | 11 | ps.io(function(err,io){ 12 | 13 | console.log('my process has done this much io',io); 14 | 15 | }) 16 | 17 | ``` 18 | 19 | this only works on linux right now i expect. some things may work on other systems that have some support for procfs. 20 | 21 | ## hope 22 | 23 | it would be so cool to have a higher level module that unifies system monitoring scripts in such a way as each os specific implementation can export a common interface like this and we can have xplatform monitoring helpers!! does windows have any external process introspection api?! 24 | 25 | ## API 26 | 27 | * procfs(pid) 28 | * ps.io(cb) 29 | * ps.stat(cb) 30 | * ps.statm(cb) 31 | * ps.status(cb) 32 | * ps.env(cb) 33 | * ps.cwd(cb) 34 | * ps.argv(cb) 35 | * ps.fds(cb) 36 | * ps.threads(cb) 37 | * ps.thread(tid) 38 | * procfs.cpu(cb) 39 | * procfs.meminfo(cb) 40 | * procfs.fd(cb) 41 | * procfs.tcp(cb) 42 | * procfs.udp(cb) 43 | * procfs.unix(cb) 44 | * procfs.net(cb) 45 | * procfs.disk(cb) 46 | * procfs.wifi(cb) 47 | * procfs.works() 48 | 49 | 50 | 51 | ### procfs(pid) 52 | - returns PidStats ps 53 | - PidStats is an object with methods documented blelow with the prefix "ps." 54 | 55 | ```js 56 | 57 | var ps = procfs(process.pid) 58 | console.log(ps); 59 | 60 | ``` 61 | 62 | 63 | ### ps.io(cb) 64 | - from /proc/pid/io 65 | - disk io stats 66 | 67 | ```js 68 | 69 | { rchar: '84167', 70 | wchar: '15978', 71 | syscr: '107', 72 | syscw: '47', 73 | read_bytes: '0', 74 | write_bytes: '12288', 75 | cancelled_write_bytes: '0' } 76 | 77 | ``` 78 | 79 | 80 | ### ps.stat(cb) 81 | - from /proc/pid/stat 82 | - mixed detailed process stats 83 | - calls back with 84 | 85 | ```js 86 | 87 | { pid: '8157', 88 | comm: '(node)', 89 | state: 'R', 90 | ppid: '8156', 91 | pgrp: '8150', 92 | session: '1703', 93 | tty_nr: '34822', 94 | tpgid: '8150', 95 | flags: '4202496', 96 | minflt: '3788', 97 | cminflt: '0', 98 | majflt: '0', 99 | cmajflt: '0', 100 | utime: '8', 101 | stime: '1', 102 | cutime: '0', 103 | cstime: '0', 104 | priority: '20', 105 | nice: '0', 106 | num_threads: '6', 107 | itrealvalue: '0', 108 | starttime: '62912348', 109 | vsize: '910020608', 110 | rss: '3277', 111 | rsslim: '18446744073709551615', 112 | startcode: '4194304', 113 | endcode: '12964340', 114 | startstack: '140736757717536', 115 | kstkesp: '140736757701400', 116 | kstkeip: '140541704641018', 117 | signal: '0', 118 | blocked: '0', 119 | sigignore: '4096', 120 | sigcatch: '16898', 121 | wchan: '18446744073709551615', 122 | nswap: '0', 123 | cnswap: '0', 124 | exit_signal: '17', 125 | processor: '0', 126 | rt_priority: '0', 127 | policy: '0', 128 | delayacct_blkio_ticks: '0', 129 | guest_time: '0', 130 | cguest_time: '0' } 131 | 132 | ``` 133 | 134 | 135 | ### ps.statm(cb) 136 | - from /proc/pid/statm 137 | - memory stats 138 | - calls back with an object of mem stats 139 | 140 | ```js 141 | 142 | { size: '222173', 143 | resident: '3342', 144 | share: '1284', 145 | text: '2142', 146 | lib: '0', 147 | data: '215399', 148 | dt: '0' } 149 | 150 | ``` 151 | 152 | 153 | ### ps.status(cb) 154 | - from /proc/pid/status 155 | - mixed process stats with more human friendly formatting 156 | 157 | ```js 158 | 159 | { Name: 'node', 160 | State: 'S (sleeping)', 161 | Tgid: '8157', 162 | Pid: '8157', 163 | PPid: '8156', 164 | TracerPid: '0', 165 | Uid: '1000\t1000\t1000\t1000', 166 | Gid: '1000\t1000\t1000\t1000', 167 | FDSize: '64', 168 | Groups: '4 20 24 27 30 46 109 121 1000 ', 169 | VmPeak: '954740 kB', 170 | VmSize: '888692 kB', 171 | VmLck: '0 kB', 172 | VmPin: '0 kB', 173 | VmHWM: '13464 kB', 174 | VmRSS: '13368 kB', 175 | VmData: '861452 kB', 176 | VmStk: '144 kB', 177 | VmExe: '8568 kB', 178 | VmLib: '4084 kB', 179 | VmPTE: '172 kB', 180 | VmSwap: '0 kB', 181 | Threads: '6', 182 | SigQ: '2/63628', 183 | SigPnd: '0000000000000000', 184 | ShdPnd: '0000000000000000', 185 | SigBlk: '0000000000000000', 186 | SigIgn: '0000000000001000', 187 | SigCgt: '0000000180004202', 188 | CapInh: '0000000000000000', 189 | CapPrm: '0000000000000000', 190 | CapEff: '0000000000000000', 191 | CapBnd: 'ffffffffffffffff', 192 | Cpus_allowed: 'ff', 193 | Cpus_allowed_list: '0-7', 194 | Mems_allowed: '00000000,00000001', 195 | Mems_allowed_list: '0', 196 | voluntary_ctxt_switches: '39', 197 | nonvoluntary_ctxt_switches: '29' } 198 | 199 | ``` 200 | 201 | 202 | ### ps.env(cb) 203 | - from /proc/pid/environ 204 | - calls back with the array of environment variables as they were defined when the process started. 205 | 206 | ```js 207 | 208 | [ ... 209 | 'MANPATH=:/usr/local/avr/man:/usr/local/avr/man', 210 | 'LS_OPTIONS=--color=auto', 211 | 'npm_config_git=git', 212 | 'npm_config_optional=true', 213 | 'EDITOR=vim', 214 | 'npm_config_email=soldair@', 215 | 'npm_config_json=' ] 216 | 217 | ``` 218 | 219 | 220 | ### ps.cwd(cb) 221 | - from /proc/pid/cwd 222 | - calls back with the working directory of the process when it was started 223 | 224 | ```js 225 | 226 | "/home/soldair/opensource/node-procfs-stats" 227 | 228 | ``` 229 | 230 | ### ps.argv(cb) 231 | - from /proc/pid/cmdline 232 | - calls back with an array of command line arguments used to run the target process 233 | 234 | these are the args for the command ```node test/pid_argv.js --example``` 235 | 236 | ```js 237 | [ 'node', 238 | 'test/pid_argv.js', 239 | '--example' ] 240 | ``` 241 | 242 | 243 | ### ps.fds(cb) 244 | - from /proc/pid/fds 245 | - returns an array of paths to file descriptors in the procfs fds directory for this process. 246 | 247 | ```js 248 | 249 | [ '/proc/8157/fd/0', 250 | '/proc/8157/fd/1', 251 | '/proc/8157/fd/10', 252 | '/proc/8157/fd/2', 253 | '/proc/8157/fd/9' ] 254 | 255 | ``` 256 | 257 | 258 | ### ps.threads(cb) 259 | - from /proc/pid/tasks 260 | - calls back with an array of the ids/names of each task in the procfs task dir for that pid. 261 | 262 | ```js 263 | 264 | [ '10299', '10300', '10301', '10302', '10303', '10304' ] 265 | 266 | ``` 267 | 268 | 269 | ### ps.thread(tid) 270 | - returns PidStats object for taskid 271 | 272 | the exported function also has these "static" methods. 273 | 274 | ```js 275 | 276 | var thread = ps.thread(tid); 277 | 278 | ``` 279 | 280 | 281 | ### procfs.cpu(cb) 282 | - from /proc/stat 283 | - calls back with an object like this 284 | 285 | ```js 286 | 287 | { cpu: 288 | { user: '22865094', 289 | nice: '8419', 290 | system: '41080741', 291 | idle: '120838211', 292 | iowait: '31250', 293 | irq: '13', 294 | softirq: '38550', 295 | steal: '0', 296 | guest: '0', 297 | guest_nice: '0' }, 298 | cpu0: 299 | { user: '5417204', 300 | nice: '1535', 301 | system: '8517931', 302 | idle: '32167970', 303 | iowait: '13554', 304 | irq: '10', 305 | softirq: '33485', 306 | steal: '0', 307 | guest: '0', 308 | guest_nice: '0' }, 309 | ... more cpus 310 | intr: '779069953 10 0 0 ... so many zeros ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', 311 | ctxt: '1272813489', 312 | btime: '1389119192', 313 | processes: '104169', 314 | procs_running: '2', 315 | procs_blocked: '0', 316 | softirq: '387055666 39 219612430 63769 2305517 2468782 39 16208198 61170901 82217 85143774' } 317 | 318 | ``` 319 | 320 | 321 | ### procfs.meminfo(cb) 322 | - from /proc/meminfo 323 | - calls back with an object like this 324 | 325 | ```js 326 | 327 | { MemTotal: '1019452', 328 | MemFree: '44328', 329 | MemAvailable: '438588', 330 | Buffers: '110444', 331 | Cached: '233468', 332 | SwapCached: '0', 333 | Active: '745748', 334 | Inactive: '136524', 335 | 'Active(anon)': '538432', 336 | 'Inactive(anon)': '64', 337 | 'Active(file)': '207316', 338 | 'Inactive(file)': '136460', 339 | Unevictable: '0', 340 | Mlocked: '0', 341 | SwapTotal: '0', 342 | SwapFree: '0', 343 | Dirty: '25788', 344 | Writeback: '0', 345 | AnonPages: '538432', 346 | Mapped: '76296', 347 | Shmem: '136', 348 | Slab: '75952', 349 | SReclaimable: '65052', 350 | SUnreclaim: '10900', 351 | KernelStack: '2880', 352 | PageTables: '5264', 353 | NFS_Unstable: '0', 354 | Bounce: '0', 355 | WritebackTmp: '0', 356 | CommitLimit: '509724', 357 | Committed_AS: '1070328', 358 | VmallocTotal: '34359738367', 359 | VmallocUsed: '2528', 360 | VmallocChunk: '34359729003', 361 | AnonHugePages: '0', 362 | HugePages_Total: '0', 363 | HugePages_Free: '0', 364 | HugePages_Rsvd: '0', 365 | HugePages_Surp: '0', 366 | Hugepagesize: '2048', 367 | DirectMap4k: '22528', 368 | DirectMap2M: '1026048' } 369 | 370 | ``` 371 | 372 | 373 | ### procfs.fd(fdPath,cb) 374 | - from /proc/pid/fds/fd and /proc/pid/fdinfo 375 | - fdPath is the full path 376 | - calls back with an object 377 | - stat is an fs.Stats object 378 | - full path to file. 379 | - in the case of a socket a string "socket[inode]" or some such will be returned. you can lookup the inode in the net.tcp||udp||unix table for even more info! 380 | 381 | ```js 382 | 383 | { fd: '/proc/8306/fd/2', 384 | path: '/dev/pts/6', 385 | info: { pos: '0', flags: '02100002' }, 386 | stat: 387 | { dev: 11, 388 | mode: 8576, 389 | nlink: 1, 390 | uid: 1000, 391 | gid: 5, 392 | rdev: 34822, 393 | blksize: 1024, 394 | ino: 9, 395 | size: 0, 396 | blocks: 0, 397 | atime: Tue Jan 14 2014 17:19:04 GMT-0800 (PST), 398 | mtime: Tue Jan 14 2014 17:19:04 GMT-0800 (PST), 399 | ctime: Thu Jan 09 2014 14:28:29 GMT-0800 (PST) } 400 | 401 | // if its not a regular file path supported by stat stat is false. 402 | 403 | { path: 'pipe:[19705393]', 404 | info: { pos: '0', flags: '02000000' }, 405 | stat: false } 406 | 407 | { path: 'anon_inode:[eventfd]', 408 | info: { pos: '0', flags: '02004002' }, 409 | stat: false } 410 | 411 | ``` 412 | 413 | 414 | ### procfs.tcp(cb) 415 | - from /proc/net/tcp 416 | - the tcp connection table as an array 417 | - used to count connections/servers and get throughput per active connection 418 | - note "extra" fields that appear after inode in the text file for tcp connections are placed under the _ key which is an object keyed off of the field offset of the value 419 | 420 | ```js 421 | [ .... 422 | { sl: '10:', 423 | local_address: '127.0.0.1:24599', 424 | rem_address: '0.0.0.0:0', 425 | st: '0A', 426 | tx_queue: '00000000', 427 | rx_queue: '00000000', 428 | tr: '00', 429 | 'tm->when': '00000000', 430 | retrnsmt: '00000000', 431 | uid: '118', 432 | timeout: '0', 433 | inode: '12881', 434 | _: 435 | { '12': '1', 436 | '13': '0000000000000000', 437 | '14': '100', 438 | '15': '0', 439 | '16': '0', 440 | '17': '10', 441 | '18': '-1' } } ] 442 | 443 | ``` 444 | 445 | 446 | ### procfs.udp(cb) 447 | - from /proc/net/udp 448 | - the udp connection table as an array 449 | - used to count listeners/server and get throughput 450 | 451 | ```js 452 | 453 | [ { sl: '1186:', 454 | local_address: '127.0.0.1:52011', 455 | rem_address: '0.0.0.0:0', 456 | st: '07', 457 | tx_queue: '00000000', 458 | rx_queue: '00000000', 459 | tr: '00', 460 | 'tm->when': '00000000', 461 | retrnsmt: '00000000', 462 | uid: '116', 463 | timeout: '0', 464 | inode: '12576', 465 | ref: '2', 466 | pointer: '0000000000000000', 467 | drops: '0' }, 468 | ... ] 469 | 470 | ``` 471 | 472 | 473 | ### procfs.unix(cb) 474 | - from /proc/net/unix 475 | - the unix socket table as an array 476 | 477 | ```js 478 | [ { Num: '0000000000000000:', 479 | RefCount: '00000002', 480 | Protocol: '00000000', 481 | Flags: '00010000', 482 | Type: '0001', 483 | St: '01', 484 | Inode: '12597', 485 | Path: '/var/run/mysqld/mysqld.sock' }, 486 | ...] 487 | ``` 488 | 489 | 490 | ### procfs.net(cb) 491 | - from /proc/net/dev 492 | - calls back with and array of all network devices along with stats 493 | 494 | ```js 495 | 496 | [{ Interface: 'wlan0:', 497 | bytes: { Receive: '301155854', Transmit: '75294312' }, 498 | packets: { Receive: '910966', Transmit: '372927' }, 499 | errs: { Receive: '0', Transmit: '0' }, 500 | drop: { Receive: '0', Transmit: '0' }, 501 | fifo: { Receive: '0', Transmit: '0' }, 502 | frame: { Receive: '0' }, 503 | compressed: { Receive: '0', Transmit: '0' }, 504 | multicast: { Receive: '0' }, 505 | colls: { Transmit: '0' }, 506 | carrier: { Transmit: '0' } }, 507 | { Interface: 'eth0:', 508 | bytes: { Receive: '1202562365', Transmit: '111732378' }, 509 | packets: { Receive: '1868620', Transmit: '608933' }, 510 | errs: { Receive: '0', Transmit: '0' }, 511 | drop: { Receive: '0', Transmit: '0' }, 512 | fifo: { Receive: '0', Transmit: '0' }, 513 | frame: { Receive: '0' }, 514 | compressed: { Receive: '0', Transmit: '0' }, 515 | multicast: { Receive: '102222' }, 516 | colls: { Transmit: '0' }, 517 | carrier: { Transmit: '0' } }] 518 | 519 | ``` 520 | 521 | 522 | ### procfs.disk(cb) 523 | - from /proc/diskstats 524 | - call back format: cb(false, data, buf), where data looks like below 525 | 526 | ```js 527 | 528 | [ { device_number: '1', 529 | device_number_minor: '5', 530 | device: 'ram5', 531 | reads_completed: '0', 532 | reads_merged: '0', 533 | sectors_read: '0', 534 | ms_reading: '0', 535 | writes_completed: '0', 536 | writes_merged: '0', 537 | sectors_written: '0', 538 | ms_writing: '0', 539 | ios_pending: '0', 540 | ms_io: '0', 541 | ms_weighted_io: '0' }, 542 | ... many disks or disk like things... 543 | { device_number: '8', 544 | device_number_minor: '0', 545 | device: 'sda', 546 | reads_completed: '255428', 547 | reads_merged: '208748', 548 | sectors_read: '9462489', 549 | ms_reading: '368008', 550 | writes_completed: '1604578', 551 | writes_merged: '735675', 552 | sectors_written: '36575515', 553 | ms_writing: '1680932', 554 | ios_pending: '0', 555 | ms_io: '410844', 556 | ms_weighted_io: '2101936' } ] 557 | 558 | ``` 559 | 560 | 561 | ### procfs.wifi(cb) 562 | - from /proc/net/wireless 563 | - calls back with wifi defices and stats 564 | 565 | ```js 566 | [ { Interface: 'wlan0:', 567 | status: '0000', 568 | link: { Quality: '51.' }, 569 | level: { Quality: '-59.' }, 570 | noise: { Quality: '-256' }, 571 | nwid: { 'Discarded packets': '0' }, 572 | crypt: { 'Discarded packets': '0' }, 573 | frag: { 'Discarded packets': '0' }, 574 | retry: { 'Discarded packets': '40' }, 575 | misc: { 'Discarded packets': '54' }, 576 | beacon: { Missed: '0' } } ] 577 | ``` 578 | 579 | 580 | 581 | ### procfs.works === true||false 582 | - fs.exists on /proc 583 | - if the procfs can be accessed this value is true 584 | 585 | ```js 586 | 587 | if(!procfs.works) process.exit('oh no!') 588 | 589 | ``` 590 | -------------------------------------------------------------------------------- /diskstats.md: -------------------------------------------------------------------------------- 1 | /proc/diskstats 2 | 3 | https://www.kernel.org/doc/Documentation/iostats.txt 4 | 5 | Each set of stats only applies to the indicated device; if you want 6 | system-wide stats you'll have to find all the devices and sum them all up. 7 | 8 | Field 1 -- # of reads completed 9 | This is the total number of reads completed successfully. 10 | Field 2 -- # of reads merged, field 6 -- # of writes merged 11 | Reads and writes which are adjacent to each other may be merged for 12 | efficiency. Thus two 4K reads may become one 8K read before it is 13 | ultimately handed to the disk, and so it will be counted (and queued) 14 | as only one I/O. This field lets you know how often this was done. 15 | Field 3 -- # of sectors read 16 | This is the total number of sectors read successfully. 17 | Field 4 -- # of milliseconds spent reading 18 | This is the total number of milliseconds spent by all reads (as 19 | measured from __make_request() to end_that_request_last()). 20 | Field 5 -- # of writes completed 21 | This is the total number of writes completed successfully. 22 | Field 6 -- # of writes merged 23 | See the description of field 2. 24 | Field 7 -- # of sectors written 25 | This is the total number of sectors written successfully. 26 | Field 8 -- # of milliseconds spent writing 27 | This is the total number of milliseconds spent by all writes (as 28 | measured from __make_request() to end_that_request_last()). 29 | Field 9 -- # of I/Os currently in progress 30 | The only field that should go to zero. Incremented as requests are 31 | given to appropriate struct request_queue and decremented as they finish. 32 | Field 10 -- # of milliseconds spent doing I/Os 33 | This field increases so long as field 9 is nonzero. 34 | Field 11 -- weighted # of milliseconds spent doing I/Os 35 | This field is incremented at each I/O start, I/O completion, I/O 36 | merge, or read of these stats by the number of I/Os in progress 37 | (field 9) times the number of milliseconds spent doing I/O since the 38 | last update of this field. This can provide an easy measure of both 39 | I/O completion time and the backlog that may be accumulating. 40 | 41 | 42 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var once = require('once') 2 | var fs = require('fs'); 3 | var hexip = require('hexip'); 4 | var parseaddr = require('./lib/parse-addr') 5 | var nettable = require('./lib/nettable') 6 | 7 | // read the procfs stat file for a pid 8 | module.exports = function(pid/*,procpath*/,cb){ // or task: ":pid/task/:tid" 9 | 10 | var pp = _pp(arguments,1); 11 | var procPath = pp.procPath 12 | cb = pp.cb; 13 | 14 | var o = { 15 | pid:pid, 16 | stat:function(cb){ 17 | fs.readFile(procPath+pid+'/stat',function(err,data){ 18 | if(err) return cb(err); 19 | var values = data.toString().trim().split(" "); 20 | cb(false,assoc(module.exports.fields['/proc/:pid/stat'],values)); 21 | }); 22 | }, 23 | // memory stat file 24 | statm:function(cb){ 25 | fs.readFile(procPath+pid+'/statm',function(err,buf){ 26 | if(err) return cb(err); 27 | var values = buf.toString().trim().split(/\s+/g) 28 | cb(false,assoc(module.exports.fields['/proc/:pid/statm'],values)) 29 | }) 30 | }, 31 | // status is a human version of most but not all of the data in both stat and statm 32 | status:function(cb){ 33 | fs.readFile(procPath+pid+'/status',function(err,buf){ 34 | cb(err,kv(buf)); 35 | }); 36 | }, 37 | argv:function(cb){ 38 | fs.readFile(procPath+pid+'/cmdline',function(err,buf){ 39 | cb(err,nulldelim(buf)); 40 | }); 41 | }, 42 | env:function(cb){ 43 | fs.readFile(procPath+pid+'/environ',function(err,buf){ 44 | cb(err,nulldelim(buf)); 45 | }); 46 | }, 47 | cwd:function(cb){ 48 | fs.readlink(procPath+pid+"/cwd",function(err,path){ 49 | cb(err,path); 50 | }) 51 | }, 52 | io:function(cb){ 53 | fs.readFile(procPath+pid+'/io',function(err,buf){ 54 | if(err) return cb(err); 55 | cb(false,kv(buf)); 56 | }); 57 | }, 58 | fds:function(cb){ 59 | var fddir = procPath+pid+'/fd'; 60 | fs.readdir(fddir,function(err,fds){ 61 | if(err) return cb(err); 62 | fds = fds.map(function(v){ 63 | return fddir+'/'+v; 64 | }); 65 | cb(false,fds); 66 | }) 67 | }, 68 | threads:function(cb){ 69 | // read the number of threads running out of the tasks dir 70 | var fddir = procPath+pid+'/task'; 71 | fs.readdir(fddir,function(err,fds){ 72 | if(err) return cb(err); 73 | //fds = fds.map(function(v){ 74 | //return {id:v,path:ddir+'/'+v}; 75 | //}); 76 | cb(false,fds); 77 | }) 78 | }, 79 | thread:function(tid){ 80 | return module.exports(pid+"/task/"+tid); 81 | }, 82 | net:function(cb){ 83 | cb = once(cb) 84 | var c = 2 85 | 86 | var tcp; 87 | var fds; 88 | 89 | 90 | module.exports.tcp(procPath,function(err,data){ 91 | if(err) return cb(err) 92 | 93 | tcp = data 94 | next() 95 | }) 96 | 97 | this.fds(function(err,data){ 98 | 99 | if(err) return cb(err) 100 | 101 | var fds = {} 102 | var todo = data.length; 103 | if(!todo) return next() 104 | 105 | function work(){ 106 | if(!data.length) return; 107 | var fd = data.shift() 108 | fs.readlink(fd,function(err,path){ 109 | // the fd may not exist anymore. 110 | if(err) return next(); 111 | 112 | fds[fd] = path; 113 | if(!--todo) next() 114 | }) 115 | } 116 | 117 | var conc = 10 118 | while(conc-- > 0) work() 119 | 120 | }) 121 | 122 | function next(){ 123 | if(--c) return work() 124 | 125 | // find socket fds in tcp nettable 126 | 127 | console.log(nettable) 128 | console.log(fds) 129 | 130 | } 131 | } 132 | } 133 | 134 | return o; 135 | }; 136 | 137 | 138 | // path to /proc 139 | module.exports.PROC = '/proc/'; 140 | 141 | 142 | // stat fd, get full path, get type/socket type.. 143 | module.exports.fd = function(fdlink,cb){ 144 | 145 | fs.readlink(fdlink,function(err,p){ 146 | if(err) return cb(err); 147 | var infop = fdlink.split('/'); 148 | var id = infop.pop(); 149 | 150 | var out = { 151 | fd:fdlink, 152 | path:p, 153 | info:false, 154 | stat:false 155 | } 156 | 157 | infop = infop.join('/')+'info/'+id; 158 | 159 | var c = 1, done = function(){ 160 | if(!--c) cb(false,out); 161 | } 162 | 163 | fs.readFile(infop,function(err,fdinfo){ 164 | if(err) return cb(err); 165 | out.info = kv(fdinfo); 166 | done(); 167 | }); 168 | 169 | if(p.indexOf('/') === 0) { 170 | c++; 171 | fs.stat(p,function(err,stat){ 172 | // ignore enoent probably 173 | if(err) return cb(err); 174 | out.stat = stat; 175 | done(); 176 | }) 177 | } 178 | }); 179 | } 180 | 181 | module.exports.cpu = function(cb){ 182 | 183 | var pp = _pp(arguments); 184 | var procPath = pp.procPath 185 | cb = pp.cb; 186 | 187 | fs.readFile(procPath+'stat',function(err,buf){ 188 | if(err) return cb(err); 189 | var lines = buf.toString().trim().split("\n"); 190 | 191 | var o = {}; 192 | lines.forEach(function(l){ 193 | var p = l.indexOf(' '); 194 | var k = l.substr(0,p); 195 | var v = l.substr(p).trim(); 196 | 197 | o[k] = v; 198 | if(k.indexOf('cpu') === 0) { 199 | o[k] = assoc(module.exports.fields['/proc/stat'].cpu,v.split(' ')); 200 | } 201 | }) 202 | 203 | cb(false,o); 204 | 205 | }); 206 | } 207 | 208 | module.exports.meminfo = function (cb){ 209 | 210 | var pp = _pp(arguments); 211 | var procPath = pp.procPath 212 | cb = pp.cb; 213 | 214 | fs.readFile(procPath+'meminfo',function(err,buf){ 215 | if(err) return cb(err); 216 | var lines = buf.toString().trim().split("\n"); 217 | 218 | var o = {}; 219 | lines.forEach(function(l){ 220 | var p = l.indexOf(':'); 221 | var k = l.substr(0,p); 222 | var v = l.substr(p + 1).replace(/kB/,'').trim(); 223 | 224 | o[k] = v; 225 | }) 226 | 227 | cb(false,o); 228 | 229 | }); 230 | } 231 | 232 | // active tcp 233 | module.exports.tcp = function(cb){ 234 | var pp = _pp(arguments); 235 | var procPath = pp.procPath 236 | cb = pp.cb; 237 | 238 | fs.readFile(procPath+"net/tcp",function(err,buf){ 239 | if(err) return cb(err); 240 | var t = nettable(buf); 241 | t.forEach(function(con){ 242 | con.rem_address = parseaddr(con.rem_address); 243 | con.local_address = parseaddr(con.local_address); 244 | }); 245 | cb(null,t,buf); 246 | }); 247 | } 248 | 249 | // active udp 250 | module.exports.udp = function(cb){ 251 | var pp = _pp(arguments); 252 | var procPath = pp.procPath 253 | cb = pp.cb; 254 | 255 | 256 | fs.readFile(procPath+"net/udp",function(err,buf){ 257 | if(err) return cb(err); 258 | var t = nettable(buf); 259 | t.forEach(function(con){ 260 | con.rem_address = parseaddr(con.rem_address); 261 | con.local_address = parseaddr(con.local_address); 262 | }); 263 | cb(null,t,buf); 264 | }); 265 | } 266 | 267 | // active unix 268 | module.exports.unix = function(cb){ 269 | var pp = _pp(arguments); 270 | var procPath = pp.procPath 271 | cb = pp.cb; 272 | 273 | fs.readFile(procPath+"net/unix",function(err,buf){ 274 | if(err) return cb(err); 275 | var lines = buf.toString().trim().split("\n"); 276 | var keys = lines.shift().trim().split(/\s+/); 277 | var out = []; 278 | lines.forEach(function(l){ 279 | out.push(assoc(keys,l.trim().split(/\s+/))) 280 | }); 281 | cb(null,out,buf); 282 | }); 283 | } 284 | 285 | // net dev stats per NIC 286 | module.exports.net = function(cb){ 287 | var pp = _pp(arguments); 288 | var procPath = pp.procPath 289 | cb = pp.cb; 290 | 291 | fs.readFile(procPath+"net/dev",function(err,buf){ 292 | if(err) return cb(err); 293 | cb(err,sectiontable(buf),buf); 294 | }); 295 | } 296 | 297 | // wifi stats 298 | module.exports.wifi = function(cb){ 299 | var pp = _pp(arguments); 300 | var procPath = pp.procPath 301 | cb = pp.cb; 302 | 303 | fs.readFile(procPath+"net/wireless",function(err,buf){ 304 | if(err) return cb(err); 305 | cb(null,sectiontable(buf),buf); 306 | }); 307 | } 308 | 309 | module.exports.disk = function(cb){ 310 | var pp = _pp(arguments); 311 | var procPath = pp.procPath 312 | cb = pp.cb; 313 | 314 | 315 | fs.readFile(procPath+"diskstats",function(err,buf){ 316 | if(err) return cb(err); 317 | 318 | var lines = buf.toString().trim().split("\n"); 319 | var out = [] 320 | lines.forEach(function(l){ 321 | out.push(assoc(module.exports.fields['/proc/diskstats'],l.trim().split(/\s+/))) 322 | }) 323 | cb(false,out,buf); 324 | }); 325 | 326 | } 327 | 328 | 329 | //i wonder if this is useful? you have to be root to get it. 330 | // its not documented and the nr of the syscall though its supposed to be first never gives me the value i expect in the syscall mapping table. 331 | // i checked unistd.h and a few other places for the __NR nr int value it must be another number not listed. 332 | //module.exports.syscall = function(){ 333 | //http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/diff/fs/proc/base.c?id=ebcb67341fee34061430f3367f2e507e52ee051b 334 | //+ "%ld 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n", 335 | //+ nr, 336 | //+ args[0], args[1], args[2], args[3], args[4], args[5], 337 | //+ sp, pc); 338 | // 339 | // 232 0x5 0x7fff89a352b0 0x400 0x3e8 0x44 0x7fff89a382f0 0x7fff89a38220 0x7f042d9a9619 340 | // 232 0x5 0x7fff89a352b0 0x400 0x7d0 0x2214350 0x7fff89a382f0 0x7fff89a38158 0x7f042d9a9619 341 | //} 342 | 343 | module.exports.fields = { 344 | '/proc/stat':{ 345 | cpu:['user','nice','system','idle','iowait','irq','softirq','steal','guest','guest_nice'] 346 | }, 347 | '/proc/:pid/stat':[ 348 | 'pid','comm','state','ppid','pgrp','session','tty_nr','tpgid','flags' 349 | ,'minflt','cminflt','majflt','cmajflt','utime','stime','cutime','cstime' 350 | ,'priority','nice','num_threads','itrealvalue','starttime','vsize','rss' 351 | ,'rsslim','startcode','endcode','startstack','kstkesp','kstkeip','signal' 352 | ,'blocked','sigignore','sigcatch','wchan','nswap','cnswap','exit_signal' 353 | ,'processor','rt_priority','policy','delayacct_blkio_ticks','guest_time' 354 | ,'cguest_time' 355 | ], 356 | '/proc/:pid/statm':[ 357 | "size" // total program size 358 | // (same as VmSize in /proc/[pid]/status) 359 | ,"resident"// resident set size 360 | // (same as VmRSS in /proc/[pid]/status) 361 | ,"share" // shared pages (from shared mappings) 362 | ,"text" // text (code) 363 | ,"lib" // library (unused in Linux 2.6) 364 | ,"data" // data + stack 365 | ,"dt" // dirty pages (unused in Linux 2.6) 366 | ], 367 | '/proc/diskstats':[ 368 | "device_number","device_number_minor","device" 369 | ,"reads_completed","reads_merged","sectors_read","ms_reading" 370 | ,"writes_completed","writes_merged","sectors_written","ms_writing" 371 | ,"ios_pending","ms_io","ms_weighted_io" 372 | ] 373 | } 374 | 375 | 376 | // works on linuxy /proc 377 | module.exports.works = fs.existsSync('/proc/'+process.pid+'/stat'); 378 | 379 | function assoc(fields,values){ 380 | var o = {}; 381 | values.forEach(function(v,i){ 382 | if(fields.length <= i) { 383 | if(!o._) o._ = {}; 384 | o._[i] = v; 385 | } else o[fields[i]] = v; 386 | }); 387 | return o; 388 | } 389 | 390 | function kv(buf){ 391 | if(!buf) return false; 392 | var info = {}; 393 | var lines = buf.toString().split("\n"); 394 | lines.forEach(function(l){ 395 | var matches = l.match(/^([^:]+):[\s]+(.+)$/); 396 | if(!matches) return; 397 | info[matches[1]] = matches[2]; 398 | }); 399 | return info; 400 | } 401 | 402 | 403 | function sectiontable(buf){ 404 | if(!buf) return false; 405 | var lines = buf.toString().trim().split("\n"); 406 | var sections = lines.shift(); 407 | 408 | var columns = lines.shift().trim().split('|'); 409 | var sections = sections.split('|'); 410 | 411 | var s,l,c,p = 0,map = {},keys = []; 412 | for(var i=0;i", 10 | "license": "MIT", 11 | "devDependencies": { 12 | "tape": "~2.3.2" 13 | }, 14 | "dependencies": { 15 | "hexip": "~1.0.1", 16 | "lru-cache": "^4.0.0", 17 | "once": "^1.3.3" 18 | }, 19 | "repository": { 20 | "url": "git://github.com/soldair/node-procfs-stats.git" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /proc.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | T H E /proc F I L E S Y S T E M 3 | ------------------------------------------------------------------------------ 4 | /proc/sys Terrehon Bowden October 7 1999 5 | Bodo Bauer 6 | 7 | 2.4.x update Jorge Nerin November 14 2000 8 | move /proc/sys Shen Feng April 1 2009 9 | ------------------------------------------------------------------------------ 10 | Version 1.3 Kernel version 2.2.12 11 | Kernel version 2.4.0-test11-pre4 12 | ------------------------------------------------------------------------------ 13 | fixes/update part 1.1 Stefani Seibold June 9 2009 14 | 15 | Table of Contents 16 | ----------------- 17 | 18 | 0 Preface 19 | 0.1 Introduction/Credits 20 | 0.2 Legal Stuff 21 | 22 | 1 Collecting System Information 23 | 1.1 Process-Specific Subdirectories 24 | 1.2 Kernel data 25 | 1.3 IDE devices in /proc/ide 26 | 1.4 Networking info in /proc/net 27 | 1.5 SCSI info 28 | 1.6 Parallel port info in /proc/parport 29 | 1.7 TTY info in /proc/tty 30 | 1.8 Miscellaneous kernel statistics in /proc/stat 31 | 1.9 Ext4 file system parameters 32 | 33 | 2 Modifying System Parameters 34 | 35 | 3 Per-Process Parameters 36 | 3.1 /proc//oom_adj & /proc//oom_score_adj - Adjust the oom-killer 37 | score 38 | 3.2 /proc//oom_score - Display current oom-killer score 39 | 3.3 /proc//io - Display the IO accounting fields 40 | 3.4 /proc//coredump_filter - Core dump filtering settings 41 | 3.5 /proc//mountinfo - Information about mounts 42 | 3.6 /proc//comm & /proc//task//comm 43 | 3.7 /proc//task//children - Information about task children 44 | 3.8 /proc//fdinfo/ - Information about opened file 45 | 46 | 4 Configuring procfs 47 | 4.1 Mount options 48 | 49 | ------------------------------------------------------------------------------ 50 | Preface 51 | ------------------------------------------------------------------------------ 52 | 53 | 0.1 Introduction/Credits 54 | ------------------------ 55 | 56 | This documentation is part of a soon (or so we hope) to be released book on 57 | the SuSE Linux distribution. As there is no complete documentation for the 58 | /proc file system and we've used many freely available sources to write these 59 | chapters, it seems only fair to give the work back to the Linux community. 60 | This work is based on the 2.2.* kernel version and the upcoming 2.4.*. I'm 61 | afraid it's still far from complete, but we hope it will be useful. As far as 62 | we know, it is the first 'all-in-one' document about the /proc file system. It 63 | is focused on the Intel x86 hardware, so if you are looking for PPC, ARM, 64 | SPARC, AXP, etc., features, you probably won't find what you are looking for. 65 | It also only covers IPv4 networking, not IPv6 nor other protocols - sorry. But 66 | additions and patches are welcome and will be added to this document if you 67 | mail them to Bodo. 68 | 69 | We'd like to thank Alan Cox, Rik van Riel, and Alexey Kuznetsov and a lot of 70 | other people for help compiling this documentation. We'd also like to extend a 71 | special thank you to Andi Kleen for documentation, which we relied on heavily 72 | to create this document, as well as the additional information he provided. 73 | Thanks to everybody else who contributed source or docs to the Linux kernel 74 | and helped create a great piece of software... :) 75 | 76 | If you have any comments, corrections or additions, please don't hesitate to 77 | contact Bodo Bauer at bb@ricochet.net. We'll be happy to add them to this 78 | document. 79 | 80 | The latest version of this document is available online at 81 | http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html 82 | 83 | If the above direction does not works for you, you could try the kernel 84 | mailing list at linux-kernel@vger.kernel.org and/or try to reach me at 85 | comandante@zaralinux.com. 86 | 87 | 0.2 Legal Stuff 88 | --------------- 89 | 90 | We don't guarantee the correctness of this document, and if you come to us 91 | complaining about how you screwed up your system because of incorrect 92 | documentation, we won't feel responsible... 93 | 94 | ------------------------------------------------------------------------------ 95 | CHAPTER 1: COLLECTING SYSTEM INFORMATION 96 | ------------------------------------------------------------------------------ 97 | 98 | ------------------------------------------------------------------------------ 99 | In This Chapter 100 | ------------------------------------------------------------------------------ 101 | * Investigating the properties of the pseudo file system /proc and its 102 | ability to provide information on the running Linux system 103 | * Examining /proc's structure 104 | * Uncovering various information about the kernel and the processes running 105 | on the system 106 | ------------------------------------------------------------------------------ 107 | 108 | 109 | The proc file system acts as an interface to internal data structures in the 110 | kernel. It can be used to obtain information about the system and to change 111 | certain kernel parameters at runtime (sysctl). 112 | 113 | First, we'll take a look at the read-only parts of /proc. In Chapter 2, we 114 | show you how you can use /proc/sys to change settings. 115 | 116 | 1.1 Process-Specific Subdirectories 117 | ----------------------------------- 118 | 119 | The directory /proc contains (among other things) one subdirectory for each 120 | process running on the system, which is named after the process ID (PID). 121 | 122 | The link self points to the process reading the file system. Each process 123 | subdirectory has the entries listed in Table 1-1. 124 | 125 | 126 | Table 1-1: Process specific entries in /proc 127 | .............................................................................. 128 | File Content 129 | clear_refs Clears page referenced bits shown in smaps output 130 | cmdline Command line arguments 131 | cpu Current and last cpu in which it was executed (2.4)(smp) 132 | cwd Link to the current working directory 133 | environ Values of environment variables 134 | exe Link to the executable of this process 135 | fd Directory, which contains all file descriptors 136 | maps Memory maps to executables and library files (2.4) 137 | mem Memory held by this process 138 | root Link to the root directory of this process 139 | stat Process status 140 | statm Process memory status information 141 | status Process status in human readable form 142 | wchan If CONFIG_KALLSYMS is set, a pre-decoded wchan 143 | pagemap Page table 144 | stack Report full stack trace, enable via CONFIG_STACKTRACE 145 | smaps a extension based on maps, showing the memory consumption of 146 | each mapping and flags associated with it 147 | .............................................................................. 148 | 149 | For example, to get the status information of a process, all you have to do is 150 | read the file /proc/PID/status: 151 | 152 | >cat /proc/self/status 153 | Name: cat 154 | State: R (running) 155 | Tgid: 5452 156 | Pid: 5452 157 | PPid: 743 158 | TracerPid: 0 (2.4) 159 | Uid: 501 501 501 501 160 | Gid: 100 100 100 100 161 | FDSize: 256 162 | Groups: 100 14 16 163 | VmPeak: 5004 kB 164 | VmSize: 5004 kB 165 | VmLck: 0 kB 166 | VmHWM: 476 kB 167 | VmRSS: 476 kB 168 | VmData: 156 kB 169 | VmStk: 88 kB 170 | VmExe: 68 kB 171 | VmLib: 1412 kB 172 | VmPTE: 20 kb 173 | VmSwap: 0 kB 174 | Threads: 1 175 | SigQ: 0/28578 176 | SigPnd: 0000000000000000 177 | ShdPnd: 0000000000000000 178 | SigBlk: 0000000000000000 179 | SigIgn: 0000000000000000 180 | SigCgt: 0000000000000000 181 | CapInh: 00000000fffffeff 182 | CapPrm: 0000000000000000 183 | CapEff: 0000000000000000 184 | CapBnd: ffffffffffffffff 185 | Seccomp: 0 186 | voluntary_ctxt_switches: 0 187 | nonvoluntary_ctxt_switches: 1 188 | 189 | This shows you nearly the same information you would get if you viewed it with 190 | the ps command. In fact, ps uses the proc file system to obtain its 191 | information. But you get a more detailed view of the process by reading the 192 | file /proc/PID/status. It fields are described in table 1-2. 193 | 194 | The statm file contains more detailed information about the process 195 | memory usage. Its seven fields are explained in Table 1-3. The stat file 196 | contains details information about the process itself. Its fields are 197 | explained in Table 1-4. 198 | 199 | (for SMP CONFIG users) 200 | For making accounting scalable, RSS related information are handled in 201 | asynchronous manner and the vaule may not be very precise. To see a precise 202 | snapshot of a moment, you can see /proc//smaps file and scan page table. 203 | It's slow but very precise. 204 | 205 | Table 1-2: Contents of the status files (as of 2.6.30-rc7) 206 | .............................................................................. 207 | Field Content 208 | Name filename of the executable 209 | State state (R is running, S is sleeping, D is sleeping 210 | in an uninterruptible wait, Z is zombie, 211 | T is traced or stopped) 212 | Tgid thread group ID 213 | Pid process id 214 | PPid process id of the parent process 215 | TracerPid PID of process tracing this process (0 if not) 216 | Uid Real, effective, saved set, and file system UIDs 217 | Gid Real, effective, saved set, and file system GIDs 218 | FDSize number of file descriptor slots currently allocated 219 | Groups supplementary group list 220 | VmPeak peak virtual memory size 221 | VmSize total program size 222 | VmLck locked memory size 223 | VmHWM peak resident set size ("high water mark") 224 | VmRSS size of memory portions 225 | VmData size of data, stack, and text segments 226 | VmStk size of data, stack, and text segments 227 | VmExe size of text segment 228 | VmLib size of shared library code 229 | VmPTE size of page table entries 230 | VmSwap size of swap usage (the number of referred swapents) 231 | Threads number of threads 232 | SigQ number of signals queued/max. number for queue 233 | SigPnd bitmap of pending signals for the thread 234 | ShdPnd bitmap of shared pending signals for the process 235 | SigBlk bitmap of blocked signals 236 | SigIgn bitmap of ignored signals 237 | SigCgt bitmap of catched signals 238 | CapInh bitmap of inheritable capabilities 239 | CapPrm bitmap of permitted capabilities 240 | CapEff bitmap of effective capabilities 241 | CapBnd bitmap of capabilities bounding set 242 | Seccomp seccomp mode, like prctl(PR_GET_SECCOMP, ...) 243 | Cpus_allowed mask of CPUs on which this process may run 244 | Cpus_allowed_list Same as previous, but in "list format" 245 | Mems_allowed mask of memory nodes allowed to this process 246 | Mems_allowed_list Same as previous, but in "list format" 247 | voluntary_ctxt_switches number of voluntary context switches 248 | nonvoluntary_ctxt_switches number of non voluntary context switches 249 | .............................................................................. 250 | 251 | Table 1-3: Contents of the statm files (as of 2.6.8-rc3) 252 | .............................................................................. 253 | Field Content 254 | size total program size (pages) (same as VmSize in status) 255 | resident size of memory portions (pages) (same as VmRSS in status) 256 | shared number of pages that are shared (i.e. backed by a file) 257 | trs number of pages that are 'code' (not including libs; broken, 258 | includes data segment) 259 | lrs number of pages of library (always 0 on 2.6) 260 | drs number of pages of data/stack (including libs; broken, 261 | includes library text) 262 | dt number of dirty pages (always 0 on 2.6) 263 | .............................................................................. 264 | 265 | 266 | Table 1-4: Contents of the stat files (as of 2.6.30-rc7) 267 | .............................................................................. 268 | Field Content 269 | pid process id 270 | tcomm filename of the executable 271 | state state (R is running, S is sleeping, D is sleeping in an 272 | uninterruptible wait, Z is zombie, T is traced or stopped) 273 | ppid process id of the parent process 274 | pgrp pgrp of the process 275 | sid session id 276 | tty_nr tty the process uses 277 | tty_pgrp pgrp of the tty 278 | flags task flags 279 | min_flt number of minor faults 280 | cmin_flt number of minor faults with child's 281 | maj_flt number of major faults 282 | cmaj_flt number of major faults with child's 283 | utime user mode jiffies 284 | stime kernel mode jiffies 285 | cutime user mode jiffies with child's 286 | cstime kernel mode jiffies with child's 287 | priority priority level 288 | nice nice level 289 | num_threads number of threads 290 | it_real_value (obsolete, always 0) 291 | start_time time the process started after system boot 292 | vsize virtual memory size 293 | rss resident set memory size 294 | rsslim current limit in bytes on the rss 295 | start_code address above which program text can run 296 | end_code address below which program text can run 297 | start_stack address of the start of the main process stack 298 | esp current value of ESP 299 | eip current value of EIP 300 | pending bitmap of pending signals 301 | blocked bitmap of blocked signals 302 | sigign bitmap of ignored signals 303 | sigcatch bitmap of catched signals 304 | wchan address where process went to sleep 305 | 0 (place holder) 306 | 0 (place holder) 307 | exit_signal signal to send to parent thread on exit 308 | task_cpu which CPU the task is scheduled on 309 | rt_priority realtime priority 310 | policy scheduling policy (man sched_setscheduler) 311 | blkio_ticks time spent waiting for block IO 312 | gtime guest time of the task in jiffies 313 | cgtime guest time of the task children in jiffies 314 | start_data address above which program data+bss is placed 315 | end_data address below which program data+bss is placed 316 | start_brk address above which program heap can be expanded with brk() 317 | arg_start address above which program command line is placed 318 | arg_end address below which program command line is placed 319 | env_start address above which program environment is placed 320 | env_end address below which program environment is placed 321 | exit_code the thread's exit_code in the form reported by the waitpid system call 322 | .............................................................................. 323 | 324 | The /proc/PID/maps file containing the currently mapped memory regions and 325 | their access permissions. 326 | 327 | The format is: 328 | 329 | address perms offset dev inode pathname 330 | 331 | 08048000-08049000 r-xp 00000000 03:00 8312 /opt/test 332 | 08049000-0804a000 rw-p 00001000 03:00 8312 /opt/test 333 | 0804a000-0806b000 rw-p 00000000 00:00 0 [heap] 334 | a7cb1000-a7cb2000 ---p 00000000 00:00 0 335 | a7cb2000-a7eb2000 rw-p 00000000 00:00 0 336 | a7eb2000-a7eb3000 ---p 00000000 00:00 0 337 | a7eb3000-a7ed5000 rw-p 00000000 00:00 0 [stack:1001] 338 | a7ed5000-a8008000 r-xp 00000000 03:00 4222 /lib/libc.so.6 339 | a8008000-a800a000 r--p 00133000 03:00 4222 /lib/libc.so.6 340 | a800a000-a800b000 rw-p 00135000 03:00 4222 /lib/libc.so.6 341 | a800b000-a800e000 rw-p 00000000 00:00 0 342 | a800e000-a8022000 r-xp 00000000 03:00 14462 /lib/libpthread.so.0 343 | a8022000-a8023000 r--p 00013000 03:00 14462 /lib/libpthread.so.0 344 | a8023000-a8024000 rw-p 00014000 03:00 14462 /lib/libpthread.so.0 345 | a8024000-a8027000 rw-p 00000000 00:00 0 346 | a8027000-a8043000 r-xp 00000000 03:00 8317 /lib/ld-linux.so.2 347 | a8043000-a8044000 r--p 0001b000 03:00 8317 /lib/ld-linux.so.2 348 | a8044000-a8045000 rw-p 0001c000 03:00 8317 /lib/ld-linux.so.2 349 | aff35000-aff4a000 rw-p 00000000 00:00 0 [stack] 350 | ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso] 351 | 352 | where "address" is the address space in the process that it occupies, "perms" 353 | is a set of permissions: 354 | 355 | r = read 356 | w = write 357 | x = execute 358 | s = shared 359 | p = private (copy on write) 360 | 361 | "offset" is the offset into the mapping, "dev" is the device (major:minor), and 362 | "inode" is the inode on that device. 0 indicates that no inode is associated 363 | with the memory region, as the case would be with BSS (uninitialized data). 364 | The "pathname" shows the name associated file for this mapping. If the mapping 365 | is not associated with a file: 366 | 367 | [heap] = the heap of the program 368 | [stack] = the stack of the main process 369 | [stack:1001] = the stack of the thread with tid 1001 370 | [vdso] = the "virtual dynamic shared object", 371 | the kernel system call handler 372 | 373 | or if empty, the mapping is anonymous. 374 | 375 | The /proc/PID/task/TID/maps is a view of the virtual memory from the viewpoint 376 | of the individual tasks of a process. In this file you will see a mapping marked 377 | as [stack] if that task sees it as a stack. This is a key difference from the 378 | content of /proc/PID/maps, where you will see all mappings that are being used 379 | as stack by all of those tasks. Hence, for the example above, the task-level 380 | map, i.e. /proc/PID/task/TID/maps for thread 1001 will look like this: 381 | 382 | 08048000-08049000 r-xp 00000000 03:00 8312 /opt/test 383 | 08049000-0804a000 rw-p 00001000 03:00 8312 /opt/test 384 | 0804a000-0806b000 rw-p 00000000 00:00 0 [heap] 385 | a7cb1000-a7cb2000 ---p 00000000 00:00 0 386 | a7cb2000-a7eb2000 rw-p 00000000 00:00 0 387 | a7eb2000-a7eb3000 ---p 00000000 00:00 0 388 | a7eb3000-a7ed5000 rw-p 00000000 00:00 0 [stack] 389 | a7ed5000-a8008000 r-xp 00000000 03:00 4222 /lib/libc.so.6 390 | a8008000-a800a000 r--p 00133000 03:00 4222 /lib/libc.so.6 391 | a800a000-a800b000 rw-p 00135000 03:00 4222 /lib/libc.so.6 392 | a800b000-a800e000 rw-p 00000000 00:00 0 393 | a800e000-a8022000 r-xp 00000000 03:00 14462 /lib/libpthread.so.0 394 | a8022000-a8023000 r--p 00013000 03:00 14462 /lib/libpthread.so.0 395 | a8023000-a8024000 rw-p 00014000 03:00 14462 /lib/libpthread.so.0 396 | a8024000-a8027000 rw-p 00000000 00:00 0 397 | a8027000-a8043000 r-xp 00000000 03:00 8317 /lib/ld-linux.so.2 398 | a8043000-a8044000 r--p 0001b000 03:00 8317 /lib/ld-linux.so.2 399 | a8044000-a8045000 rw-p 0001c000 03:00 8317 /lib/ld-linux.so.2 400 | aff35000-aff4a000 rw-p 00000000 00:00 0 401 | ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso] 402 | 403 | The /proc/PID/smaps is an extension based on maps, showing the memory 404 | consumption for each of the process's mappings. For each of mappings there 405 | is a series of lines such as the following: 406 | 407 | 08048000-080bc000 r-xp 00000000 03:02 13130 /bin/bash 408 | Size: 1084 kB 409 | Rss: 892 kB 410 | Pss: 374 kB 411 | Shared_Clean: 892 kB 412 | Shared_Dirty: 0 kB 413 | Private_Clean: 0 kB 414 | Private_Dirty: 0 kB 415 | Referenced: 892 kB 416 | Anonymous: 0 kB 417 | Swap: 0 kB 418 | KernelPageSize: 4 kB 419 | MMUPageSize: 4 kB 420 | Locked: 374 kB 421 | VmFlags: rd ex mr mw me de 422 | 423 | the first of these lines shows the same information as is displayed for the 424 | mapping in /proc/PID/maps. The remaining lines show the size of the mapping 425 | (size), the amount of the mapping that is currently resident in RAM (RSS), the 426 | process' proportional share of this mapping (PSS), the number of clean and 427 | dirty private pages in the mapping. Note that even a page which is part of a 428 | MAP_SHARED mapping, but has only a single pte mapped, i.e. is currently used 429 | by only one process, is accounted as private and not as shared. "Referenced" 430 | indicates the amount of memory currently marked as referenced or accessed. 431 | "Anonymous" shows the amount of memory that does not belong to any file. Even 432 | a mapping associated with a file may contain anonymous pages: when MAP_PRIVATE 433 | and a page is modified, the file page is replaced by a private anonymous copy. 434 | "Swap" shows how much would-be-anonymous memory is also used, but out on 435 | swap. 436 | 437 | "VmFlags" field deserves a separate description. This member represents the kernel 438 | flags associated with the particular virtual memory area in two letter encoded 439 | manner. The codes are the following: 440 | rd - readable 441 | wr - writeable 442 | ex - executable 443 | sh - shared 444 | mr - may read 445 | mw - may write 446 | me - may execute 447 | ms - may share 448 | gd - stack segment growns down 449 | pf - pure PFN range 450 | dw - disabled write to the mapped file 451 | lo - pages are locked in memory 452 | io - memory mapped I/O area 453 | sr - sequential read advise provided 454 | rr - random read advise provided 455 | dc - do not copy area on fork 456 | de - do not expand area on remapping 457 | ac - area is accountable 458 | nr - swap space is not reserved for the area 459 | ht - area uses huge tlb pages 460 | nl - non-linear mapping 461 | ar - architecture specific flag 462 | dd - do not include area into core dump 463 | sd - soft-dirty flag 464 | mm - mixed map area 465 | hg - huge page advise flag 466 | nh - no-huge page advise flag 467 | mg - mergable advise flag 468 | 469 | Note that there is no guarantee that every flag and associated mnemonic will 470 | be present in all further kernel releases. Things get changed, the flags may 471 | be vanished or the reverse -- new added. 472 | 473 | This file is only present if the CONFIG_MMU kernel configuration option is 474 | enabled. 475 | 476 | The /proc/PID/clear_refs is used to reset the PG_Referenced and ACCESSED/YOUNG 477 | bits on both physical and virtual pages associated with a process, and the 478 | soft-dirty bit on pte (see Documentation/vm/soft-dirty.txt for details). 479 | To clear the bits for all the pages associated with the process 480 | > echo 1 > /proc/PID/clear_refs 481 | 482 | To clear the bits for the anonymous pages associated with the process 483 | > echo 2 > /proc/PID/clear_refs 484 | 485 | To clear the bits for the file mapped pages associated with the process 486 | > echo 3 > /proc/PID/clear_refs 487 | 488 | To clear the soft-dirty bit 489 | > echo 4 > /proc/PID/clear_refs 490 | 491 | Any other value written to /proc/PID/clear_refs will have no effect. 492 | 493 | The /proc/pid/pagemap gives the PFN, which can be used to find the pageflags 494 | using /proc/kpageflags and number of times a page is mapped using 495 | /proc/kpagecount. For detailed explanation, see Documentation/vm/pagemap.txt. 496 | 497 | 1.2 Kernel data 498 | --------------- 499 | 500 | Similar to the process entries, the kernel data files give information about 501 | the running kernel. The files used to obtain this information are contained in 502 | /proc and are listed in Table 1-5. Not all of these will be present in your 503 | system. It depends on the kernel configuration and the loaded modules, which 504 | files are there, and which are missing. 505 | 506 | Table 1-5: Kernel info in /proc 507 | .............................................................................. 508 | File Content 509 | apm Advanced power management info 510 | buddyinfo Kernel memory allocator information (see text) (2.5) 511 | bus Directory containing bus specific information 512 | cmdline Kernel command line 513 | cpuinfo Info about the CPU 514 | devices Available devices (block and character) 515 | dma Used DMS channels 516 | filesystems Supported filesystems 517 | driver Various drivers grouped here, currently rtc (2.4) 518 | execdomains Execdomains, related to security (2.4) 519 | fb Frame Buffer devices (2.4) 520 | fs File system parameters, currently nfs/exports (2.4) 521 | ide Directory containing info about the IDE subsystem 522 | interrupts Interrupt usage 523 | iomem Memory map (2.4) 524 | ioports I/O port usage 525 | irq Masks for irq to cpu affinity (2.4)(smp?) 526 | isapnp ISA PnP (Plug&Play) Info (2.4) 527 | kcore Kernel core image (can be ELF or A.OUT(deprecated in 2.4)) 528 | kmsg Kernel messages 529 | ksyms Kernel symbol table 530 | loadavg Load average of last 1, 5 & 15 minutes 531 | locks Kernel locks 532 | meminfo Memory info 533 | misc Miscellaneous 534 | modules List of loaded modules 535 | mounts Mounted filesystems 536 | net Networking info (see text) 537 | pagetypeinfo Additional page allocator information (see text) (2.5) 538 | partitions Table of partitions known to the system 539 | pci Deprecated info of PCI bus (new way -> /proc/bus/pci/, 540 | decoupled by lspci (2.4) 541 | rtc Real time clock 542 | scsi SCSI info (see text) 543 | slabinfo Slab pool info 544 | softirqs softirq usage 545 | stat Overall statistics 546 | swaps Swap space utilization 547 | sys See chapter 2 548 | sysvipc Info of SysVIPC Resources (msg, sem, shm) (2.4) 549 | tty Info of tty drivers 550 | uptime System uptime 551 | version Kernel version 552 | video bttv info of video resources (2.4) 553 | vmallocinfo Show vmalloced areas 554 | .............................................................................. 555 | 556 | You can, for example, check which interrupts are currently in use and what 557 | they are used for by looking in the file /proc/interrupts: 558 | 559 | > cat /proc/interrupts 560 | CPU0 561 | 0: 8728810 XT-PIC timer 562 | 1: 895 XT-PIC keyboard 563 | 2: 0 XT-PIC cascade 564 | 3: 531695 XT-PIC aha152x 565 | 4: 2014133 XT-PIC serial 566 | 5: 44401 XT-PIC pcnet_cs 567 | 8: 2 XT-PIC rtc 568 | 11: 8 XT-PIC i82365 569 | 12: 182918 XT-PIC PS/2 Mouse 570 | 13: 1 XT-PIC fpu 571 | 14: 1232265 XT-PIC ide0 572 | 15: 7 XT-PIC ide1 573 | NMI: 0 574 | 575 | In 2.4.* a couple of lines where added to this file LOC & ERR (this time is the 576 | output of a SMP machine): 577 | 578 | > cat /proc/interrupts 579 | 580 | CPU0 CPU1 581 | 0: 1243498 1214548 IO-APIC-edge timer 582 | 1: 8949 8958 IO-APIC-edge keyboard 583 | 2: 0 0 XT-PIC cascade 584 | 5: 11286 10161 IO-APIC-edge soundblaster 585 | 8: 1 0 IO-APIC-edge rtc 586 | 9: 27422 27407 IO-APIC-edge 3c503 587 | 12: 113645 113873 IO-APIC-edge PS/2 Mouse 588 | 13: 0 0 XT-PIC fpu 589 | 14: 22491 24012 IO-APIC-edge ide0 590 | 15: 2183 2415 IO-APIC-edge ide1 591 | 17: 30564 30414 IO-APIC-level eth0 592 | 18: 177 164 IO-APIC-level bttv 593 | NMI: 2457961 2457959 594 | LOC: 2457882 2457881 595 | ERR: 2155 596 | 597 | NMI is incremented in this case because every timer interrupt generates a NMI 598 | (Non Maskable Interrupt) which is used by the NMI Watchdog to detect lockups. 599 | 600 | LOC is the local interrupt counter of the internal APIC of every CPU. 601 | 602 | ERR is incremented in the case of errors in the IO-APIC bus (the bus that 603 | connects the CPUs in a SMP system. This means that an error has been detected, 604 | the IO-APIC automatically retry the transmission, so it should not be a big 605 | problem, but you should read the SMP-FAQ. 606 | 607 | In 2.6.2* /proc/interrupts was expanded again. This time the goal was for 608 | /proc/interrupts to display every IRQ vector in use by the system, not 609 | just those considered 'most important'. The new vectors are: 610 | 611 | THR -- interrupt raised when a machine check threshold counter 612 | (typically counting ECC corrected errors of memory or cache) exceeds 613 | a configurable threshold. Only available on some systems. 614 | 615 | TRM -- a thermal event interrupt occurs when a temperature threshold 616 | has been exceeded for the CPU. This interrupt may also be generated 617 | when the temperature drops back to normal. 618 | 619 | SPU -- a spurious interrupt is some interrupt that was raised then lowered 620 | by some IO device before it could be fully processed by the APIC. Hence 621 | the APIC sees the interrupt but does not know what device it came from. 622 | For this case the APIC will generate the interrupt with a IRQ vector 623 | of 0xff. This might also be generated by chipset bugs. 624 | 625 | RES, CAL, TLB -- rescheduling, call and TLB flush interrupts are 626 | sent from one CPU to another per the needs of the OS. Typically, 627 | their statistics are used by kernel developers and interested users to 628 | determine the occurrence of interrupts of the given type. 629 | 630 | The above IRQ vectors are displayed only when relevant. For example, 631 | the threshold vector does not exist on x86_64 platforms. Others are 632 | suppressed when the system is a uniprocessor. As of this writing, only 633 | i386 and x86_64 platforms support the new IRQ vector displays. 634 | 635 | Of some interest is the introduction of the /proc/irq directory to 2.4. 636 | It could be used to set IRQ to CPU affinity, this means that you can "hook" an 637 | IRQ to only one CPU, or to exclude a CPU of handling IRQs. The contents of the 638 | irq subdir is one subdir for each IRQ, and two files; default_smp_affinity and 639 | prof_cpu_mask. 640 | 641 | For example 642 | > ls /proc/irq/ 643 | 0 10 12 14 16 18 2 4 6 8 prof_cpu_mask 644 | 1 11 13 15 17 19 3 5 7 9 default_smp_affinity 645 | > ls /proc/irq/0/ 646 | smp_affinity 647 | 648 | smp_affinity is a bitmask, in which you can specify which CPUs can handle the 649 | IRQ, you can set it by doing: 650 | 651 | > echo 1 > /proc/irq/10/smp_affinity 652 | 653 | This means that only the first CPU will handle the IRQ, but you can also echo 654 | 5 which means that only the first and fourth CPU can handle the IRQ. 655 | 656 | The contents of each smp_affinity file is the same by default: 657 | 658 | > cat /proc/irq/0/smp_affinity 659 | ffffffff 660 | 661 | There is an alternate interface, smp_affinity_list which allows specifying 662 | a cpu range instead of a bitmask: 663 | 664 | > cat /proc/irq/0/smp_affinity_list 665 | 1024-1031 666 | 667 | The default_smp_affinity mask applies to all non-active IRQs, which are the 668 | IRQs which have not yet been allocated/activated, and hence which lack a 669 | /proc/irq/[0-9]* directory. 670 | 671 | The node file on an SMP system shows the node to which the device using the IRQ 672 | reports itself as being attached. This hardware locality information does not 673 | include information about any possible driver locality preference. 674 | 675 | prof_cpu_mask specifies which CPUs are to be profiled by the system wide 676 | profiler. Default value is ffffffff (all cpus if there are only 32 of them). 677 | 678 | The way IRQs are routed is handled by the IO-APIC, and it's Round Robin 679 | between all the CPUs which are allowed to handle it. As usual the kernel has 680 | more info than you and does a better job than you, so the defaults are the 681 | best choice for almost everyone. [Note this applies only to those IO-APIC's 682 | that support "Round Robin" interrupt distribution.] 683 | 684 | There are three more important subdirectories in /proc: net, scsi, and sys. 685 | The general rule is that the contents, or even the existence of these 686 | directories, depend on your kernel configuration. If SCSI is not enabled, the 687 | directory scsi may not exist. The same is true with the net, which is there 688 | only when networking support is present in the running kernel. 689 | 690 | The slabinfo file gives information about memory usage at the slab level. 691 | Linux uses slab pools for memory management above page level in version 2.2. 692 | Commonly used objects have their own slab pool (such as network buffers, 693 | directory cache, and so on). 694 | 695 | .............................................................................. 696 | 697 | > cat /proc/buddyinfo 698 | 699 | Node 0, zone DMA 0 4 5 4 4 3 ... 700 | Node 0, zone Normal 1 0 0 1 101 8 ... 701 | Node 0, zone HighMem 2 0 0 1 1 0 ... 702 | 703 | External fragmentation is a problem under some workloads, and buddyinfo is a 704 | useful tool for helping diagnose these problems. Buddyinfo will give you a 705 | clue as to how big an area you can safely allocate, or why a previous 706 | allocation failed. 707 | 708 | Each column represents the number of pages of a certain order which are 709 | available. In this case, there are 0 chunks of 2^0*PAGE_SIZE available in 710 | ZONE_DMA, 4 chunks of 2^1*PAGE_SIZE in ZONE_DMA, 101 chunks of 2^4*PAGE_SIZE 711 | available in ZONE_NORMAL, etc... 712 | 713 | More information relevant to external fragmentation can be found in 714 | pagetypeinfo. 715 | 716 | > cat /proc/pagetypeinfo 717 | Page block order: 9 718 | Pages per block: 512 719 | 720 | Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10 721 | Node 0, zone DMA, type Unmovable 0 0 0 1 1 1 1 1 1 1 0 722 | Node 0, zone DMA, type Reclaimable 0 0 0 0 0 0 0 0 0 0 0 723 | Node 0, zone DMA, type Movable 1 1 2 1 2 1 1 0 1 0 2 724 | Node 0, zone DMA, type Reserve 0 0 0 0 0 0 0 0 0 1 0 725 | Node 0, zone DMA, type Isolate 0 0 0 0 0 0 0 0 0 0 0 726 | Node 0, zone DMA32, type Unmovable 103 54 77 1 1 1 11 8 7 1 9 727 | Node 0, zone DMA32, type Reclaimable 0 0 2 1 0 0 0 0 1 0 0 728 | Node 0, zone DMA32, type Movable 169 152 113 91 77 54 39 13 6 1 452 729 | Node 0, zone DMA32, type Reserve 1 2 2 2 2 0 1 1 1 1 0 730 | Node 0, zone DMA32, type Isolate 0 0 0 0 0 0 0 0 0 0 0 731 | 732 | Number of blocks type Unmovable Reclaimable Movable Reserve Isolate 733 | Node 0, zone DMA 2 0 5 1 0 734 | Node 0, zone DMA32 41 6 967 2 0 735 | 736 | Fragmentation avoidance in the kernel works by grouping pages of different 737 | migrate types into the same contiguous regions of memory called page blocks. 738 | A page block is typically the size of the default hugepage size e.g. 2MB on 739 | X86-64. By keeping pages grouped based on their ability to move, the kernel 740 | can reclaim pages within a page block to satisfy a high-order allocation. 741 | 742 | The pagetypinfo begins with information on the size of a page block. It 743 | then gives the same type of information as buddyinfo except broken down 744 | by migrate-type and finishes with details on how many page blocks of each 745 | type exist. 746 | 747 | If min_free_kbytes has been tuned correctly (recommendations made by hugeadm 748 | from libhugetlbfs http://sourceforge.net/projects/libhugetlbfs/), one can 749 | make an estimate of the likely number of huge pages that can be allocated 750 | at a given point in time. All the "Movable" blocks should be allocatable 751 | unless memory has been mlock()'d. Some of the Reclaimable blocks should 752 | also be allocatable although a lot of filesystem metadata may have to be 753 | reclaimed to achieve this. 754 | 755 | .............................................................................. 756 | 757 | meminfo: 758 | 759 | Provides information about distribution and utilization of memory. This 760 | varies by architecture and compile options. The following is from a 761 | 16GB PIII, which has highmem enabled. You may not have all of these fields. 762 | 763 | > cat /proc/meminfo 764 | 765 | The "Locked" indicates whether the mapping is locked in memory or not. 766 | 767 | 768 | MemTotal: 16344972 kB 769 | MemFree: 13634064 kB 770 | Buffers: 3656 kB 771 | Cached: 1195708 kB 772 | SwapCached: 0 kB 773 | Active: 891636 kB 774 | Inactive: 1077224 kB 775 | HighTotal: 15597528 kB 776 | HighFree: 13629632 kB 777 | LowTotal: 747444 kB 778 | LowFree: 4432 kB 779 | SwapTotal: 0 kB 780 | SwapFree: 0 kB 781 | Dirty: 968 kB 782 | Writeback: 0 kB 783 | AnonPages: 861800 kB 784 | Mapped: 280372 kB 785 | Slab: 284364 kB 786 | SReclaimable: 159856 kB 787 | SUnreclaim: 124508 kB 788 | PageTables: 24448 kB 789 | NFS_Unstable: 0 kB 790 | Bounce: 0 kB 791 | WritebackTmp: 0 kB 792 | CommitLimit: 7669796 kB 793 | Committed_AS: 100056 kB 794 | VmallocTotal: 112216 kB 795 | VmallocUsed: 428 kB 796 | VmallocChunk: 111088 kB 797 | AnonHugePages: 49152 kB 798 | 799 | MemTotal: Total usable ram (i.e. physical ram minus a few reserved 800 | bits and the kernel binary code) 801 | MemFree: The sum of LowFree+HighFree 802 | Buffers: Relatively temporary storage for raw disk blocks 803 | shouldn't get tremendously large (20MB or so) 804 | Cached: in-memory cache for files read from the disk (the 805 | pagecache). Doesn't include SwapCached 806 | SwapCached: Memory that once was swapped out, is swapped back in but 807 | still also is in the swapfile (if memory is needed it 808 | doesn't need to be swapped out AGAIN because it is already 809 | in the swapfile. This saves I/O) 810 | Active: Memory that has been used more recently and usually not 811 | reclaimed unless absolutely necessary. 812 | Inactive: Memory which has been less recently used. It is more 813 | eligible to be reclaimed for other purposes 814 | HighTotal: 815 | HighFree: Highmem is all memory above ~860MB of physical memory 816 | Highmem areas are for use by userspace programs, or 817 | for the pagecache. The kernel must use tricks to access 818 | this memory, making it slower to access than lowmem. 819 | LowTotal: 820 | LowFree: Lowmem is memory which can be used for everything that 821 | highmem can be used for, but it is also available for the 822 | kernel's use for its own data structures. Among many 823 | other things, it is where everything from the Slab is 824 | allocated. Bad things happen when you're out of lowmem. 825 | SwapTotal: total amount of swap space available 826 | SwapFree: Memory which has been evicted from RAM, and is temporarily 827 | on the disk 828 | Dirty: Memory which is waiting to get written back to the disk 829 | Writeback: Memory which is actively being written back to the disk 830 | AnonPages: Non-file backed pages mapped into userspace page tables 831 | AnonHugePages: Non-file backed huge pages mapped into userspace page tables 832 | Mapped: files which have been mmaped, such as libraries 833 | Slab: in-kernel data structures cache 834 | SReclaimable: Part of Slab, that might be reclaimed, such as caches 835 | SUnreclaim: Part of Slab, that cannot be reclaimed on memory pressure 836 | PageTables: amount of memory dedicated to the lowest level of page 837 | tables. 838 | NFS_Unstable: NFS pages sent to the server, but not yet committed to stable 839 | storage 840 | Bounce: Memory used for block device "bounce buffers" 841 | WritebackTmp: Memory used by FUSE for temporary writeback buffers 842 | CommitLimit: Based on the overcommit ratio ('vm.overcommit_ratio'), 843 | this is the total amount of memory currently available to 844 | be allocated on the system. This limit is only adhered to 845 | if strict overcommit accounting is enabled (mode 2 in 846 | 'vm.overcommit_memory'). 847 | The CommitLimit is calculated with the following formula: 848 | CommitLimit = ('vm.overcommit_ratio' * Physical RAM) + Swap 849 | For example, on a system with 1G of physical RAM and 7G 850 | of swap with a `vm.overcommit_ratio` of 30 it would 851 | yield a CommitLimit of 7.3G. 852 | For more details, see the memory overcommit documentation 853 | in vm/overcommit-accounting. 854 | Committed_AS: The amount of memory presently allocated on the system. 855 | The committed memory is a sum of all of the memory which 856 | has been allocated by processes, even if it has not been 857 | "used" by them as of yet. A process which malloc()'s 1G 858 | of memory, but only touches 300M of it will show up as 859 | using 1G. This 1G is memory which has been "committed" to 860 | by the VM and can be used at any time by the allocating 861 | application. With strict overcommit enabled on the system 862 | (mode 2 in 'vm.overcommit_memory'),allocations which would 863 | exceed the CommitLimit (detailed above) will not be permitted. 864 | This is useful if one needs to guarantee that processes will 865 | not fail due to lack of memory once that memory has been 866 | successfully allocated. 867 | VmallocTotal: total size of vmalloc memory area 868 | VmallocUsed: amount of vmalloc area which is used 869 | VmallocChunk: largest contiguous block of vmalloc area which is free 870 | 871 | .............................................................................. 872 | 873 | vmallocinfo: 874 | 875 | Provides information about vmalloced/vmaped areas. One line per area, 876 | containing the virtual address range of the area, size in bytes, 877 | caller information of the creator, and optional information depending 878 | on the kind of area : 879 | 880 | pages=nr number of pages 881 | phys=addr if a physical address was specified 882 | ioremap I/O mapping (ioremap() and friends) 883 | vmalloc vmalloc() area 884 | vmap vmap()ed pages 885 | user VM_USERMAP area 886 | vpages buffer for pages pointers was vmalloced (huge area) 887 | N=nr (Only on NUMA kernels) 888 | Number of pages allocated on memory node 889 | 890 | > cat /proc/vmallocinfo 891 | 0xffffc20000000000-0xffffc20000201000 2101248 alloc_large_system_hash+0x204 ... 892 | /0x2c0 pages=512 vmalloc N0=128 N1=128 N2=128 N3=128 893 | 0xffffc20000201000-0xffffc20000302000 1052672 alloc_large_system_hash+0x204 ... 894 | /0x2c0 pages=256 vmalloc N0=64 N1=64 N2=64 N3=64 895 | 0xffffc20000302000-0xffffc20000304000 8192 acpi_tb_verify_table+0x21/0x4f... 896 | phys=7fee8000 ioremap 897 | 0xffffc20000304000-0xffffc20000307000 12288 acpi_tb_verify_table+0x21/0x4f... 898 | phys=7fee7000 ioremap 899 | 0xffffc2000031d000-0xffffc2000031f000 8192 init_vdso_vars+0x112/0x210 900 | 0xffffc2000031f000-0xffffc2000032b000 49152 cramfs_uncompress_init+0x2e ... 901 | /0x80 pages=11 vmalloc N0=3 N1=3 N2=2 N3=3 902 | 0xffffc2000033a000-0xffffc2000033d000 12288 sys_swapon+0x640/0xac0 ... 903 | pages=2 vmalloc N1=2 904 | 0xffffc20000347000-0xffffc2000034c000 20480 xt_alloc_table_info+0xfe ... 905 | /0x130 [x_tables] pages=4 vmalloc N0=4 906 | 0xffffffffa0000000-0xffffffffa000f000 61440 sys_init_module+0xc27/0x1d00 ... 907 | pages=14 vmalloc N2=14 908 | 0xffffffffa000f000-0xffffffffa0014000 20480 sys_init_module+0xc27/0x1d00 ... 909 | pages=4 vmalloc N1=4 910 | 0xffffffffa0014000-0xffffffffa0017000 12288 sys_init_module+0xc27/0x1d00 ... 911 | pages=2 vmalloc N1=2 912 | 0xffffffffa0017000-0xffffffffa0022000 45056 sys_init_module+0xc27/0x1d00 ... 913 | pages=10 vmalloc N0=10 914 | 915 | .............................................................................. 916 | 917 | softirqs: 918 | 919 | Provides counts of softirq handlers serviced since boot time, for each cpu. 920 | 921 | > cat /proc/softirqs 922 | CPU0 CPU1 CPU2 CPU3 923 | HI: 0 0 0 0 924 | TIMER: 27166 27120 27097 27034 925 | NET_TX: 0 0 0 17 926 | NET_RX: 42 0 0 39 927 | BLOCK: 0 0 107 1121 928 | TASKLET: 0 0 0 290 929 | SCHED: 27035 26983 26971 26746 930 | HRTIMER: 0 0 0 0 931 | RCU: 1678 1769 2178 2250 932 | 933 | 934 | 1.3 IDE devices in /proc/ide 935 | ---------------------------- 936 | 937 | The subdirectory /proc/ide contains information about all IDE devices of which 938 | the kernel is aware. There is one subdirectory for each IDE controller, the 939 | file drivers and a link for each IDE device, pointing to the device directory 940 | in the controller specific subtree. 941 | 942 | The file drivers contains general information about the drivers used for the 943 | IDE devices: 944 | 945 | > cat /proc/ide/drivers 946 | ide-cdrom version 4.53 947 | ide-disk version 1.08 948 | 949 | More detailed information can be found in the controller specific 950 | subdirectories. These are named ide0, ide1 and so on. Each of these 951 | directories contains the files shown in table 1-6. 952 | 953 | 954 | Table 1-6: IDE controller info in /proc/ide/ide? 955 | .............................................................................. 956 | File Content 957 | channel IDE channel (0 or 1) 958 | config Configuration (only for PCI/IDE bridge) 959 | mate Mate name 960 | model Type/Chipset of IDE controller 961 | .............................................................................. 962 | 963 | Each device connected to a controller has a separate subdirectory in the 964 | controllers directory. The files listed in table 1-7 are contained in these 965 | directories. 966 | 967 | 968 | Table 1-7: IDE device information 969 | .............................................................................. 970 | File Content 971 | cache The cache 972 | capacity Capacity of the medium (in 512Byte blocks) 973 | driver driver and version 974 | geometry physical and logical geometry 975 | identify device identify block 976 | media media type 977 | model device identifier 978 | settings device setup 979 | smart_thresholds IDE disk management thresholds 980 | smart_values IDE disk management values 981 | .............................................................................. 982 | 983 | The most interesting file is settings. This file contains a nice overview of 984 | the drive parameters: 985 | 986 | # cat /proc/ide/ide0/hda/settings 987 | name value min max mode 988 | ---- ----- --- --- ---- 989 | bios_cyl 526 0 65535 rw 990 | bios_head 255 0 255 rw 991 | bios_sect 63 0 63 rw 992 | breada_readahead 4 0 127 rw 993 | bswap 0 0 1 r 994 | file_readahead 72 0 2097151 rw 995 | io_32bit 0 0 3 rw 996 | keepsettings 0 0 1 rw 997 | max_kb_per_request 122 1 127 rw 998 | multcount 0 0 8 rw 999 | nice1 1 0 1 rw 1000 | nowerr 0 0 1 rw 1001 | pio_mode write-only 0 255 w 1002 | slow 0 0 1 rw 1003 | unmaskirq 0 0 1 rw 1004 | using_dma 0 0 1 rw 1005 | 1006 | 1007 | 1.4 Networking info in /proc/net 1008 | -------------------------------- 1009 | 1010 | The subdirectory /proc/net follows the usual pattern. Table 1-8 shows the 1011 | additional values you get for IP version 6 if you configure the kernel to 1012 | support this. Table 1-9 lists the files and their meaning. 1013 | 1014 | 1015 | Table 1-8: IPv6 info in /proc/net 1016 | .............................................................................. 1017 | File Content 1018 | udp6 UDP sockets (IPv6) 1019 | tcp6 TCP sockets (IPv6) 1020 | raw6 Raw device statistics (IPv6) 1021 | igmp6 IP multicast addresses, which this host joined (IPv6) 1022 | if_inet6 List of IPv6 interface addresses 1023 | ipv6_route Kernel routing table for IPv6 1024 | rt6_stats Global IPv6 routing tables statistics 1025 | sockstat6 Socket statistics (IPv6) 1026 | snmp6 Snmp data (IPv6) 1027 | .............................................................................. 1028 | 1029 | 1030 | Table 1-9: Network info in /proc/net 1031 | .............................................................................. 1032 | File Content 1033 | arp Kernel ARP table 1034 | dev network devices with statistics 1035 | dev_mcast the Layer2 multicast groups a device is listening too 1036 | (interface index, label, number of references, number of bound 1037 | addresses). 1038 | dev_stat network device status 1039 | ip_fwchains Firewall chain linkage 1040 | ip_fwnames Firewall chain names 1041 | ip_masq Directory containing the masquerading tables 1042 | ip_masquerade Major masquerading table 1043 | netstat Network statistics 1044 | raw raw device statistics 1045 | route Kernel routing table 1046 | rpc Directory containing rpc info 1047 | rt_cache Routing cache 1048 | snmp SNMP data 1049 | sockstat Socket statistics 1050 | tcp TCP sockets 1051 | udp UDP sockets 1052 | unix UNIX domain sockets 1053 | wireless Wireless interface data (Wavelan etc) 1054 | igmp IP multicast addresses, which this host joined 1055 | psched Global packet scheduler parameters. 1056 | netlink List of PF_NETLINK sockets 1057 | ip_mr_vifs List of multicast virtual interfaces 1058 | ip_mr_cache List of multicast routing cache 1059 | .............................................................................. 1060 | 1061 | You can use this information to see which network devices are available in 1062 | your system and how much traffic was routed over those devices: 1063 | 1064 | > cat /proc/net/dev 1065 | Inter-|Receive |[... 1066 | face |bytes packets errs drop fifo frame compressed multicast|[... 1067 | lo: 908188 5596 0 0 0 0 0 0 [... 1068 | ppp0:15475140 20721 410 0 0 410 0 0 [... 1069 | eth0: 614530 7085 0 0 0 0 0 1 [... 1070 | 1071 | ...] Transmit 1072 | ...] bytes packets errs drop fifo colls carrier compressed 1073 | ...] 908188 5596 0 0 0 0 0 0 1074 | ...] 1375103 17405 0 0 0 0 0 0 1075 | ...] 1703981 5535 0 0 0 3 0 0 1076 | 1077 | In addition, each Channel Bond interface has its own directory. For 1078 | example, the bond0 device will have a directory called /proc/net/bond0/. 1079 | It will contain information that is specific to that bond, such as the 1080 | current slaves of the bond, the link status of the slaves, and how 1081 | many times the slaves link has failed. 1082 | 1083 | 1.5 SCSI info 1084 | ------------- 1085 | 1086 | If you have a SCSI host adapter in your system, you'll find a subdirectory 1087 | named after the driver for this adapter in /proc/scsi. You'll also see a list 1088 | of all recognized SCSI devices in /proc/scsi: 1089 | 1090 | >cat /proc/scsi/scsi 1091 | Attached devices: 1092 | Host: scsi0 Channel: 00 Id: 00 Lun: 00 1093 | Vendor: IBM Model: DGHS09U Rev: 03E0 1094 | Type: Direct-Access ANSI SCSI revision: 03 1095 | Host: scsi0 Channel: 00 Id: 06 Lun: 00 1096 | Vendor: PIONEER Model: CD-ROM DR-U06S Rev: 1.04 1097 | Type: CD-ROM ANSI SCSI revision: 02 1098 | 1099 | 1100 | The directory named after the driver has one file for each adapter found in 1101 | the system. These files contain information about the controller, including 1102 | the used IRQ and the IO address range. The amount of information shown is 1103 | dependent on the adapter you use. The example shows the output for an Adaptec 1104 | AHA-2940 SCSI adapter: 1105 | 1106 | > cat /proc/scsi/aic7xxx/0 1107 | 1108 | Adaptec AIC7xxx driver version: 5.1.19/3.2.4 1109 | Compile Options: 1110 | TCQ Enabled By Default : Disabled 1111 | AIC7XXX_PROC_STATS : Disabled 1112 | AIC7XXX_RESET_DELAY : 5 1113 | Adapter Configuration: 1114 | SCSI Adapter: Adaptec AHA-294X Ultra SCSI host adapter 1115 | Ultra Wide Controller 1116 | PCI MMAPed I/O Base: 0xeb001000 1117 | Adapter SEEPROM Config: SEEPROM found and used. 1118 | Adaptec SCSI BIOS: Enabled 1119 | IRQ: 10 1120 | SCBs: Active 0, Max Active 2, 1121 | Allocated 15, HW 16, Page 255 1122 | Interrupts: 160328 1123 | BIOS Control Word: 0x18b6 1124 | Adapter Control Word: 0x005b 1125 | Extended Translation: Enabled 1126 | Disconnect Enable Flags: 0xffff 1127 | Ultra Enable Flags: 0x0001 1128 | Tag Queue Enable Flags: 0x0000 1129 | Ordered Queue Tag Flags: 0x0000 1130 | Default Tag Queue Depth: 8 1131 | Tagged Queue By Device array for aic7xxx host instance 0: 1132 | {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255} 1133 | Actual queue depth per device for aic7xxx host instance 0: 1134 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} 1135 | Statistics: 1136 | (scsi0:0:0:0) 1137 | Device using Wide/Sync transfers at 40.0 MByte/sec, offset 8 1138 | Transinfo settings: current(12/8/1/0), goal(12/8/1/0), user(12/15/1/0) 1139 | Total transfers 160151 (74577 reads and 85574 writes) 1140 | (scsi0:0:6:0) 1141 | Device using Narrow/Sync transfers at 5.0 MByte/sec, offset 15 1142 | Transinfo settings: current(50/15/0/0), goal(50/15/0/0), user(50/15/0/0) 1143 | Total transfers 0 (0 reads and 0 writes) 1144 | 1145 | 1146 | 1.6 Parallel port info in /proc/parport 1147 | --------------------------------------- 1148 | 1149 | The directory /proc/parport contains information about the parallel ports of 1150 | your system. It has one subdirectory for each port, named after the port 1151 | number (0,1,2,...). 1152 | 1153 | These directories contain the four files shown in Table 1-10. 1154 | 1155 | 1156 | Table 1-10: Files in /proc/parport 1157 | .............................................................................. 1158 | File Content 1159 | autoprobe Any IEEE-1284 device ID information that has been acquired. 1160 | devices list of the device drivers using that port. A + will appear by the 1161 | name of the device currently using the port (it might not appear 1162 | against any). 1163 | hardware Parallel port's base address, IRQ line and DMA channel. 1164 | irq IRQ that parport is using for that port. This is in a separate 1165 | file to allow you to alter it by writing a new value in (IRQ 1166 | number or none). 1167 | .............................................................................. 1168 | 1169 | 1.7 TTY info in /proc/tty 1170 | ------------------------- 1171 | 1172 | Information about the available and actually used tty's can be found in the 1173 | directory /proc/tty.You'll find entries for drivers and line disciplines in 1174 | this directory, as shown in Table 1-11. 1175 | 1176 | 1177 | Table 1-11: Files in /proc/tty 1178 | .............................................................................. 1179 | File Content 1180 | drivers list of drivers and their usage 1181 | ldiscs registered line disciplines 1182 | driver/serial usage statistic and status of single tty lines 1183 | .............................................................................. 1184 | 1185 | To see which tty's are currently in use, you can simply look into the file 1186 | /proc/tty/drivers: 1187 | 1188 | > cat /proc/tty/drivers 1189 | pty_slave /dev/pts 136 0-255 pty:slave 1190 | pty_master /dev/ptm 128 0-255 pty:master 1191 | pty_slave /dev/ttyp 3 0-255 pty:slave 1192 | pty_master /dev/pty 2 0-255 pty:master 1193 | serial /dev/cua 5 64-67 serial:callout 1194 | serial /dev/ttyS 4 64-67 serial 1195 | /dev/tty0 /dev/tty0 4 0 system:vtmaster 1196 | /dev/ptmx /dev/ptmx 5 2 system 1197 | /dev/console /dev/console 5 1 system:console 1198 | /dev/tty /dev/tty 5 0 system:/dev/tty 1199 | unknown /dev/tty 4 1-63 console 1200 | 1201 | 1202 | 1.8 Miscellaneous kernel statistics in /proc/stat 1203 | ------------------------------------------------- 1204 | 1205 | Various pieces of information about kernel activity are available in the 1206 | /proc/stat file. All of the numbers reported in this file are aggregates 1207 | since the system first booted. For a quick look, simply cat the file: 1208 | 1209 | > cat /proc/stat 1210 | cpu 2255 34 2290 22625563 6290 127 456 0 0 1211 | cpu0 1132 34 1441 11311718 3675 127 438 0 0 1212 | cpu1 1123 0 849 11313845 2614 0 18 0 0 1213 | intr 114930548 113199788 3 0 5 263 0 4 [... lots more numbers ...] 1214 | ctxt 1990473 1215 | btime 1062191376 1216 | processes 2915 1217 | procs_running 1 1218 | procs_blocked 0 1219 | softirq 183433 0 21755 12 39 1137 231 21459 2263 1220 | 1221 | The very first "cpu" line aggregates the numbers in all of the other "cpuN" 1222 | lines. These numbers identify the amount of time the CPU has spent performing 1223 | different kinds of work. Time units are in USER_HZ (typically hundredths of a 1224 | second). The meanings of the columns are as follows, from left to right: 1225 | 1226 | - user: normal processes executing in user mode 1227 | - nice: niced processes executing in user mode 1228 | - system: processes executing in kernel mode 1229 | - idle: twiddling thumbs 1230 | - iowait: waiting for I/O to complete 1231 | - irq: servicing interrupts 1232 | - softirq: servicing softirqs 1233 | - steal: involuntary wait 1234 | - guest: running a normal guest 1235 | - guest_nice: running a niced guest 1236 | 1237 | The "intr" line gives counts of interrupts serviced since boot time, for each 1238 | of the possible system interrupts. The first column is the total of all 1239 | interrupts serviced; each subsequent column is the total for that particular 1240 | interrupt. 1241 | 1242 | The "ctxt" line gives the total number of context switches across all CPUs. 1243 | 1244 | The "btime" line gives the time at which the system booted, in seconds since 1245 | the Unix epoch. 1246 | 1247 | The "processes" line gives the number of processes and threads created, which 1248 | includes (but is not limited to) those created by calls to the fork() and 1249 | clone() system calls. 1250 | 1251 | The "procs_running" line gives the total number of threads that are 1252 | running or ready to run (i.e., the total number of runnable threads). 1253 | 1254 | The "procs_blocked" line gives the number of processes currently blocked, 1255 | waiting for I/O to complete. 1256 | 1257 | The "softirq" line gives counts of softirqs serviced since boot time, for each 1258 | of the possible system softirqs. The first column is the total of all 1259 | softirqs serviced; each subsequent column is the total for that particular 1260 | softirq. 1261 | 1262 | 1263 | 1.9 Ext4 file system parameters 1264 | ------------------------------ 1265 | 1266 | Information about mounted ext4 file systems can be found in 1267 | /proc/fs/ext4. Each mounted filesystem will have a directory in 1268 | /proc/fs/ext4 based on its device name (i.e., /proc/fs/ext4/hdc or 1269 | /proc/fs/ext4/dm-0). The files in each per-device directory are shown 1270 | in Table 1-12, below. 1271 | 1272 | Table 1-12: Files in /proc/fs/ext4/ 1273 | .............................................................................. 1274 | File Content 1275 | mb_groups details of multiblock allocator buddy cache of free blocks 1276 | .............................................................................. 1277 | 1278 | 2.0 /proc/consoles 1279 | ------------------ 1280 | Shows registered system console lines. 1281 | 1282 | To see which character device lines are currently used for the system console 1283 | /dev/console, you may simply look into the file /proc/consoles: 1284 | 1285 | > cat /proc/consoles 1286 | tty0 -WU (ECp) 4:7 1287 | ttyS0 -W- (Ep) 4:64 1288 | 1289 | The columns are: 1290 | 1291 | device name of the device 1292 | operations R = can do read operations 1293 | W = can do write operations 1294 | U = can do unblank 1295 | flags E = it is enabled 1296 | C = it is preferred console 1297 | B = it is primary boot console 1298 | p = it is used for printk buffer 1299 | b = it is not a TTY but a Braille device 1300 | a = it is safe to use when cpu is offline 1301 | major:minor major and minor number of the device separated by a colon 1302 | 1303 | ------------------------------------------------------------------------------ 1304 | Summary 1305 | ------------------------------------------------------------------------------ 1306 | The /proc file system serves information about the running system. It not only 1307 | allows access to process data but also allows you to request the kernel status 1308 | by reading files in the hierarchy. 1309 | 1310 | The directory structure of /proc reflects the types of information and makes 1311 | it easy, if not obvious, where to look for specific data. 1312 | ------------------------------------------------------------------------------ 1313 | 1314 | ------------------------------------------------------------------------------ 1315 | CHAPTER 2: MODIFYING SYSTEM PARAMETERS 1316 | ------------------------------------------------------------------------------ 1317 | 1318 | ------------------------------------------------------------------------------ 1319 | In This Chapter 1320 | ------------------------------------------------------------------------------ 1321 | * Modifying kernel parameters by writing into files found in /proc/sys 1322 | * Exploring the files which modify certain parameters 1323 | * Review of the /proc/sys file tree 1324 | ------------------------------------------------------------------------------ 1325 | 1326 | 1327 | A very interesting part of /proc is the directory /proc/sys. This is not only 1328 | a source of information, it also allows you to change parameters within the 1329 | kernel. Be very careful when attempting this. You can optimize your system, 1330 | but you can also cause it to crash. Never alter kernel parameters on a 1331 | production system. Set up a development machine and test to make sure that 1332 | everything works the way you want it to. You may have no alternative but to 1333 | reboot the machine once an error has been made. 1334 | 1335 | To change a value, simply echo the new value into the file. An example is 1336 | given below in the section on the file system data. You need to be root to do 1337 | this. You can create your own boot script to perform this every time your 1338 | system boots. 1339 | 1340 | The files in /proc/sys can be used to fine tune and monitor miscellaneous and 1341 | general things in the operation of the Linux kernel. Since some of the files 1342 | can inadvertently disrupt your system, it is advisable to read both 1343 | documentation and source before actually making adjustments. In any case, be 1344 | very careful when writing to any of these files. The entries in /proc may 1345 | change slightly between the 2.1.* and the 2.2 kernel, so if there is any doubt 1346 | review the kernel documentation in the directory /usr/src/linux/Documentation. 1347 | This chapter is heavily based on the documentation included in the pre 2.2 1348 | kernels, and became part of it in version 2.2.1 of the Linux kernel. 1349 | 1350 | Please see: Documentation/sysctl/ directory for descriptions of these 1351 | entries. 1352 | 1353 | ------------------------------------------------------------------------------ 1354 | Summary 1355 | ------------------------------------------------------------------------------ 1356 | Certain aspects of kernel behavior can be modified at runtime, without the 1357 | need to recompile the kernel, or even to reboot the system. The files in the 1358 | /proc/sys tree can not only be read, but also modified. You can use the echo 1359 | command to write value into these files, thereby changing the default settings 1360 | of the kernel. 1361 | ------------------------------------------------------------------------------ 1362 | 1363 | ------------------------------------------------------------------------------ 1364 | CHAPTER 3: PER-PROCESS PARAMETERS 1365 | ------------------------------------------------------------------------------ 1366 | 1367 | 3.1 /proc//oom_adj & /proc//oom_score_adj- Adjust the oom-killer score 1368 | -------------------------------------------------------------------------------- 1369 | 1370 | These file can be used to adjust the badness heuristic used to select which 1371 | process gets killed in out of memory conditions. 1372 | 1373 | The badness heuristic assigns a value to each candidate task ranging from 0 1374 | (never kill) to 1000 (always kill) to determine which process is targeted. The 1375 | units are roughly a proportion along that range of allowed memory the process 1376 | may allocate from based on an estimation of its current memory and swap use. 1377 | For example, if a task is using all allowed memory, its badness score will be 1378 | 1000. If it is using half of its allowed memory, its score will be 500. 1379 | 1380 | There is an additional factor included in the badness score: root 1381 | processes are given 3% extra memory over other tasks. 1382 | 1383 | The amount of "allowed" memory depends on the context in which the oom killer 1384 | was called. If it is due to the memory assigned to the allocating task's cpuset 1385 | being exhausted, the allowed memory represents the set of mems assigned to that 1386 | cpuset. If it is due to a mempolicy's node(s) being exhausted, the allowed 1387 | memory represents the set of mempolicy nodes. If it is due to a memory 1388 | limit (or swap limit) being reached, the allowed memory is that configured 1389 | limit. Finally, if it is due to the entire system being out of memory, the 1390 | allowed memory represents all allocatable resources. 1391 | 1392 | The value of /proc//oom_score_adj is added to the badness score before it 1393 | is used to determine which task to kill. Acceptable values range from -1000 1394 | (OOM_SCORE_ADJ_MIN) to +1000 (OOM_SCORE_ADJ_MAX). This allows userspace to 1395 | polarize the preference for oom killing either by always preferring a certain 1396 | task or completely disabling it. The lowest possible value, -1000, is 1397 | equivalent to disabling oom killing entirely for that task since it will always 1398 | report a badness score of 0. 1399 | 1400 | Consequently, it is very simple for userspace to define the amount of memory to 1401 | consider for each task. Setting a /proc//oom_score_adj value of +500, for 1402 | example, is roughly equivalent to allowing the remainder of tasks sharing the 1403 | same system, cpuset, mempolicy, or memory controller resources to use at least 1404 | 50% more memory. A value of -500, on the other hand, would be roughly 1405 | equivalent to discounting 50% of the task's allowed memory from being considered 1406 | as scoring against the task. 1407 | 1408 | For backwards compatibility with previous kernels, /proc//oom_adj may also 1409 | be used to tune the badness score. Its acceptable values range from -16 1410 | (OOM_ADJUST_MIN) to +15 (OOM_ADJUST_MAX) and a special value of -17 1411 | (OOM_DISABLE) to disable oom killing entirely for that task. Its value is 1412 | scaled linearly with /proc//oom_score_adj. 1413 | 1414 | The value of /proc//oom_score_adj may be reduced no lower than the last 1415 | value set by a CAP_SYS_RESOURCE process. To reduce the value any lower 1416 | requires CAP_SYS_RESOURCE. 1417 | 1418 | Caveat: when a parent task is selected, the oom killer will sacrifice any first 1419 | generation children with separate address spaces instead, if possible. This 1420 | avoids servers and important system daemons from being killed and loses the 1421 | minimal amount of work. 1422 | 1423 | 1424 | 3.2 /proc//oom_score - Display current oom-killer score 1425 | ------------------------------------------------------------- 1426 | 1427 | This file can be used to check the current score used by the oom-killer is for 1428 | any given . Use it together with /proc//oom_score_adj to tune which 1429 | process should be killed in an out-of-memory situation. 1430 | 1431 | 1432 | 3.3 /proc//io - Display the IO accounting fields 1433 | ------------------------------------------------------- 1434 | 1435 | This file contains IO statistics for each running process 1436 | 1437 | Example 1438 | ------- 1439 | 1440 | test:/tmp # dd if=/dev/zero of=/tmp/test.dat & 1441 | [1] 3828 1442 | 1443 | test:/tmp # cat /proc/3828/io 1444 | rchar: 323934931 1445 | wchar: 323929600 1446 | syscr: 632687 1447 | syscw: 632675 1448 | read_bytes: 0 1449 | write_bytes: 323932160 1450 | cancelled_write_bytes: 0 1451 | 1452 | 1453 | Description 1454 | ----------- 1455 | 1456 | rchar 1457 | ----- 1458 | 1459 | I/O counter: chars read 1460 | The number of bytes which this task has caused to be read from storage. This 1461 | is simply the sum of bytes which this process passed to read() and pread(). 1462 | It includes things like tty IO and it is unaffected by whether or not actual 1463 | physical disk IO was required (the read might have been satisfied from 1464 | pagecache) 1465 | 1466 | 1467 | wchar 1468 | ----- 1469 | 1470 | I/O counter: chars written 1471 | The number of bytes which this task has caused, or shall cause to be written 1472 | to disk. Similar caveats apply here as with rchar. 1473 | 1474 | 1475 | syscr 1476 | ----- 1477 | 1478 | I/O counter: read syscalls 1479 | Attempt to count the number of read I/O operations, i.e. syscalls like read() 1480 | and pread(). 1481 | 1482 | 1483 | syscw 1484 | ----- 1485 | 1486 | I/O counter: write syscalls 1487 | Attempt to count the number of write I/O operations, i.e. syscalls like 1488 | write() and pwrite(). 1489 | 1490 | 1491 | read_bytes 1492 | ---------- 1493 | 1494 | I/O counter: bytes read 1495 | Attempt to count the number of bytes which this process really did cause to 1496 | be fetched from the storage layer. Done at the submit_bio() level, so it is 1497 | accurate for block-backed filesystems. 1499 | 1500 | 1501 | write_bytes 1502 | ----------- 1503 | 1504 | I/O counter: bytes written 1505 | Attempt to count the number of bytes which this process caused to be sent to 1506 | the storage layer. This is done at page-dirtying time. 1507 | 1508 | 1509 | cancelled_write_bytes 1510 | --------------------- 1511 | 1512 | The big inaccuracy here is truncate. If a process writes 1MB to a file and 1513 | then deletes the file, it will in fact perform no writeout. But it will have 1514 | been accounted as having caused 1MB of write. 1515 | In other words: The number of bytes which this process caused to not happen, 1516 | by truncating pagecache. A task can cause "negative" IO too. If this task 1517 | truncates some dirty pagecache, some IO which another task has been accounted 1518 | for (in its write_bytes) will not be happening. We _could_ just subtract that 1519 | from the truncating task's write_bytes, but there is information loss in doing 1520 | that. 1521 | 1522 | 1523 | Note 1524 | ---- 1525 | 1526 | At its current implementation state, this is a bit racy on 32-bit machines: if 1527 | process A reads process B's /proc/pid/io while process B is updating one of 1528 | those 64-bit counters, process A could see an intermediate result. 1529 | 1530 | 1531 | More information about this can be found within the taskstats documentation in 1532 | Documentation/accounting. 1533 | 1534 | 3.4 /proc//coredump_filter - Core dump filtering settings 1535 | --------------------------------------------------------------- 1536 | When a process is dumped, all anonymous memory is written to a core file as 1537 | long as the size of the core file isn't limited. But sometimes we don't want 1538 | to dump some memory segments, for example, huge shared memory. Conversely, 1539 | sometimes we want to save file-backed memory segments into a core file, not 1540 | only the individual files. 1541 | 1542 | /proc//coredump_filter allows you to customize which memory segments 1543 | will be dumped when the process is dumped. coredump_filter is a bitmask 1544 | of memory types. If a bit of the bitmask is set, memory segments of the 1545 | corresponding memory type are dumped, otherwise they are not dumped. 1546 | 1547 | The following 7 memory types are supported: 1548 | - (bit 0) anonymous private memory 1549 | - (bit 1) anonymous shared memory 1550 | - (bit 2) file-backed private memory 1551 | - (bit 3) file-backed shared memory 1552 | - (bit 4) ELF header pages in file-backed private memory areas (it is 1553 | effective only if the bit 2 is cleared) 1554 | - (bit 5) hugetlb private memory 1555 | - (bit 6) hugetlb shared memory 1556 | 1557 | Note that MMIO pages such as frame buffer are never dumped and vDSO pages 1558 | are always dumped regardless of the bitmask status. 1559 | 1560 | Note bit 0-4 doesn't effect any hugetlb memory. hugetlb memory are only 1561 | effected by bit 5-6. 1562 | 1563 | Default value of coredump_filter is 0x23; this means all anonymous memory 1564 | segments and hugetlb private memory are dumped. 1565 | 1566 | If you don't want to dump all shared memory segments attached to pid 1234, 1567 | write 0x21 to the process's proc file. 1568 | 1569 | $ echo 0x21 > /proc/1234/coredump_filter 1570 | 1571 | When a new process is created, the process inherits the bitmask status from its 1572 | parent. It is useful to set up coredump_filter before the program runs. 1573 | For example: 1574 | 1575 | $ echo 0x7 > /proc/self/coredump_filter 1576 | $ ./some_program 1577 | 1578 | 3.5 /proc//mountinfo - Information about mounts 1579 | -------------------------------------------------------- 1580 | 1581 | This file contains lines of the form: 1582 | 1583 | 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue 1584 | (1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11) 1585 | 1586 | (1) mount ID: unique identifier of the mount (may be reused after umount) 1587 | (2) parent ID: ID of parent (or of self for the top of the mount tree) 1588 | (3) major:minor: value of st_dev for files on filesystem 1589 | (4) root: root of the mount within the filesystem 1590 | (5) mount point: mount point relative to the process's root 1591 | (6) mount options: per mount options 1592 | (7) optional fields: zero or more fields of the form "tag[:value]" 1593 | (8) separator: marks the end of the optional fields 1594 | (9) filesystem type: name of filesystem of the form "type[.subtype]" 1595 | (10) mount source: filesystem specific information or "none" 1596 | (11) super options: per super block options 1597 | 1598 | Parsers should ignore all unrecognised optional fields. Currently the 1599 | possible optional fields are: 1600 | 1601 | shared:X mount is shared in peer group X 1602 | master:X mount is slave to peer group X 1603 | propagate_from:X mount is slave and receives propagation from peer group X (*) 1604 | unbindable mount is unbindable 1605 | 1606 | (*) X is the closest dominant peer group under the process's root. If 1607 | X is the immediate master of the mount, or if there's no dominant peer 1608 | group under the same root, then only the "master:X" field is present 1609 | and not the "propagate_from:X" field. 1610 | 1611 | For more information on mount propagation see: 1612 | 1613 | Documentation/filesystems/sharedsubtree.txt 1614 | 1615 | 1616 | 3.6 /proc//comm & /proc//task//comm 1617 | -------------------------------------------------------- 1618 | These files provide a method to access a tasks comm value. It also allows for 1619 | a task to set its own or one of its thread siblings comm value. The comm value 1620 | is limited in size compared to the cmdline value, so writing anything longer 1621 | then the kernel's TASK_COMM_LEN (currently 16 chars) will result in a truncated 1622 | comm value. 1623 | 1624 | 1625 | 3.7 /proc//task//children - Information about task children 1626 | ------------------------------------------------------------------------- 1627 | This file provides a fast way to retrieve first level children pids 1628 | of a task pointed by / pair. The format is a space separated 1629 | stream of pids. 1630 | 1631 | Note the "first level" here -- if a child has own children they will 1632 | not be listed here, one needs to read /proc//task//children 1633 | to obtain the descendants. 1634 | 1635 | Since this interface is intended to be fast and cheap it doesn't 1636 | guarantee to provide precise results and some children might be 1637 | skipped, especially if they've exited right after we printed their 1638 | pids, so one need to either stop or freeze processes being inspected 1639 | if precise results are needed. 1640 | 1641 | 1642 | 3.7 /proc//fdinfo/ - Information about opened file 1643 | --------------------------------------------------------------- 1644 | This file provides information associated with an opened file. The regular 1645 | files have at least two fields -- 'pos' and 'flags'. The 'pos' represents 1646 | the current offset of the opened file in decimal form [see lseek(2) for 1647 | details] and 'flags' denotes the octal O_xxx mask the file has been 1648 | created with [see open(2) for details]. 1649 | 1650 | A typical output is 1651 | 1652 | pos: 0 1653 | flags: 0100002 1654 | 1655 | The files such as eventfd, fsnotify, signalfd, epoll among the regular pos/flags 1656 | pair provide additional information particular to the objects they represent. 1657 | 1658 | Eventfd files 1659 | ~~~~~~~~~~~~~ 1660 | pos: 0 1661 | flags: 04002 1662 | eventfd-count: 5a 1663 | 1664 | where 'eventfd-count' is hex value of a counter. 1665 | 1666 | Signalfd files 1667 | ~~~~~~~~~~~~~~ 1668 | pos: 0 1669 | flags: 04002 1670 | sigmask: 0000000000000200 1671 | 1672 | where 'sigmask' is hex value of the signal mask associated 1673 | with a file. 1674 | 1675 | Epoll files 1676 | ~~~~~~~~~~~ 1677 | pos: 0 1678 | flags: 02 1679 | tfd: 5 events: 1d data: ffffffffffffffff 1680 | 1681 | where 'tfd' is a target file descriptor number in decimal form, 1682 | 'events' is events mask being watched and the 'data' is data 1683 | associated with a target [see epoll(7) for more details]. 1684 | 1685 | Fsnotify files 1686 | ~~~~~~~~~~~~~~ 1687 | For inotify files the format is the following 1688 | 1689 | pos: 0 1690 | flags: 02000000 1691 | inotify wd:3 ino:9e7e sdev:800013 mask:800afce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:7e9e0000640d1b6d 1692 | 1693 | where 'wd' is a watch descriptor in decimal form, ie a target file 1694 | descriptor number, 'ino' and 'sdev' are inode and device where the 1695 | target file resides and the 'mask' is the mask of events, all in hex 1696 | form [see inotify(7) for more details]. 1697 | 1698 | If the kernel was built with exportfs support, the path to the target 1699 | file is encoded as a file handle. The file handle is provided by three 1700 | fields 'fhandle-bytes', 'fhandle-type' and 'f_handle', all in hex 1701 | format. 1702 | 1703 | If the kernel is built without exportfs support the file handle won't be 1704 | printed out. 1705 | 1706 | If there is no inotify mark attached yet the 'inotify' line will be omitted. 1707 | 1708 | For fanotify files the format is 1709 | 1710 | pos: 0 1711 | flags: 02 1712 | fanotify flags:10 event-flags:0 1713 | fanotify mnt_id:12 mflags:40 mask:38 ignored_mask:40000003 1714 | fanotify ino:4f969 sdev:800013 mflags:0 mask:3b ignored_mask:40000000 fhandle-bytes:8 fhandle-type:1 f_handle:69f90400c275b5b4 1715 | 1716 | where fanotify 'flags' and 'event-flags' are values used in fanotify_init 1717 | call, 'mnt_id' is the mount point identifier, 'mflags' is the value of 1718 | flags associated with mark which are tracked separately from events 1719 | mask. 'ino', 'sdev' are target inode and device, 'mask' is the events 1720 | mask and 'ignored_mask' is the mask of events which are to be ignored. 1721 | All in hex format. Incorporation of 'mflags', 'mask' and 'ignored_mask' 1722 | does provide information about flags and mask used in fanotify_mark 1723 | call [see fsnotify manpage for details]. 1724 | 1725 | While the first three lines are mandatory and always printed, the rest is 1726 | optional and may be omitted if no marks created yet. 1727 | 1728 | 1729 | ------------------------------------------------------------------------------ 1730 | Configuring procfs 1731 | ------------------------------------------------------------------------------ 1732 | 1733 | 4.1 Mount options 1734 | --------------------- 1735 | 1736 | The following mount options are supported: 1737 | 1738 | hidepid= Set /proc// access mode. 1739 | gid= Set the group authorized to learn processes information. 1740 | 1741 | hidepid=0 means classic mode - everybody may access all /proc// directories 1742 | (default). 1743 | 1744 | hidepid=1 means users may not access any /proc// directories but their 1745 | own. Sensitive files like cmdline, sched*, status are now protected against 1746 | other users. This makes it impossible to learn whether any user runs 1747 | specific program (given the program doesn't reveal itself by its behaviour). 1748 | As an additional bonus, as /proc//cmdline is unaccessible for other users, 1749 | poorly written programs passing sensitive information via program arguments are 1750 | now protected against local eavesdroppers. 1751 | 1752 | hidepid=2 means hidepid=1 plus all /proc// will be fully invisible to other 1753 | users. It doesn't mean that it hides a fact whether a process with a specific 1754 | pid value exists (it can be learned by other means, e.g. by "kill -0 $PID"), 1755 | but it hides process' uid and gid, which may be learned by stat()'ing 1756 | /proc// otherwise. It greatly complicates an intruder's task of gathering 1757 | information about running processes, whether some daemon runs with elevated 1758 | privileges, whether other user runs some sensitive program, whether other users 1759 | run any program at all, etc. 1760 | 1761 | gid= defines a group authorized to learn processes information otherwise 1762 | prohibited by hidepid=. If you use some daemon like identd which needs to learn 1763 | information about processes information, just add identd to this group. 1764 | -------------------------------------------------------------------------------- /test/cpu.js: -------------------------------------------------------------------------------- 1 | var test = require('tape'); 2 | var proc = require('../'); 3 | 4 | test('can read cpuinfo',function(t){ 5 | 6 | proc.cpu(function(err,data){ 7 | 8 | if(process.env.DEBUG) console.log(data); 9 | t.ok(!err,'should not have error gettijng cou'+err); 10 | t.ok(data,'should have cpu data'); 11 | t.end(); 12 | }) 13 | 14 | }) 15 | 16 | -------------------------------------------------------------------------------- /test/custompath.js: -------------------------------------------------------------------------------- 1 | var test = require('tape'); 2 | var stats = require('../'); 3 | test("can provide custom proc path",function(t){ 4 | t.plan(1); 5 | stats.disk('/fake'+Date.now(),function(err,data){ 6 | t.equals(err.code,'ENOENT','should have error getting with fake path'); 7 | }) 8 | 9 | }); 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/disk.js: -------------------------------------------------------------------------------- 1 | var test = require('tape'); 2 | var proc = require('../'); 3 | 4 | test("can get io data for disks",function(t){ 5 | proc.disk(function(err,data){ 6 | if(process.env.DEBUG) console.log(data); 7 | t.ok(!err,'should not have error '+err); 8 | t.ok(data[0].ios_pending,'should have ios_pending key if parsed correctly') 9 | t.end(); 10 | }); 11 | }) 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/fds.js: -------------------------------------------------------------------------------- 1 | var proc = require('../') 2 | , test = require('tape') 3 | ; 4 | 5 | test('can get process fds',function(t){ 6 | var p = proc(process.pid); 7 | p.fds(function(err,data){ 8 | t.ok(!err,'should not have error getting data for this pid '+err); 9 | t.ok(data.length,"should have data"); 10 | 11 | if(process.env.DEBUG) console.log(data); 12 | if(!data.length) return t.end(); 13 | 14 | var c = 0,done = function(){ 15 | c--; 16 | if(!c) t.end(); 17 | }; 18 | 19 | while(data.length) { 20 | c++; 21 | proc.fd(data.shift(),function(err,info){ 22 | if(process.env.DEBUG) console.log(err,info); 23 | done(); 24 | }); 25 | } 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /test/io.js: -------------------------------------------------------------------------------- 1 | var test = require('tape'); 2 | var proc = require('../'); 3 | 4 | test('can read cpuinfo',function(t){ 5 | 6 | var p = proc(process.pid); 7 | 8 | p.io(function(err,data){ 9 | if(process.env.DEBUG) console.log(data); 10 | t.ok(!err,'should not have error gettijng pid io'+err); 11 | t.ok(data,'should have io data'); 12 | t.end(); 13 | }) 14 | 15 | }) 16 | 17 | -------------------------------------------------------------------------------- /test/meminfo.js: -------------------------------------------------------------------------------- 1 | var test = require('tape'); 2 | var proc = require('../'); 3 | 4 | test('can read meminfo',function(t){ 5 | 6 | proc.meminfo(function(err,data){ 7 | 8 | if(process.env.DEBUG) console.log(data); 9 | t.ok(!err,'should not have error gettinng meminfo'+err); 10 | t.ok(data,'should have meminfo data'); 11 | t.end(); 12 | }) 13 | 14 | }) 15 | 16 | -------------------------------------------------------------------------------- /test/net.js: -------------------------------------------------------------------------------- 1 | var test = require('tape'); 2 | var proc = require('../'); 3 | 4 | test("can get io data for nics",function(t){ 5 | proc.net(function(err,data){ 6 | if(process.env.DEBUG) console.log(data); 7 | t.ok(!err,'should not have error '+err); 8 | t.ok(data[0].Interface,'should have interface key if parsed correctly') 9 | t.end(); 10 | }); 11 | }) 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/pid_argv.js: -------------------------------------------------------------------------------- 1 | var proc = require('../') 2 | , test = require('tape') 3 | ; 4 | 5 | test('can get prod info',function(t){ 6 | var p = proc(process.pid); 7 | 8 | p.argv(function(err,data){ 9 | t.ok(!err,'should not have error getting args for this command'+err); 10 | t.equals(data[0],'node',"should have node as the first arg"); 11 | 12 | if(process.env.DEBUG) console.log(data); 13 | 14 | t.end(); 15 | }); 16 | 17 | }) 18 | -------------------------------------------------------------------------------- /test/pid_cwd.js: -------------------------------------------------------------------------------- 1 | var proc = require('../') 2 | , test = require('tape') 3 | ; 4 | 5 | test('can get proc cwd',function(t){ 6 | var p = proc(process.pid); 7 | 8 | p.cwd(function(err,cwd){ 9 | t.ok(!err,'should not have error getting cwd for this process'+err); 10 | t.ok(cwd,"should have cwd"); 11 | 12 | if(process.env.DEBUG) console.log(cwd); 13 | 14 | t.end(); 15 | }); 16 | 17 | }) 18 | -------------------------------------------------------------------------------- /test/pid_env.js: -------------------------------------------------------------------------------- 1 | var proc = require('../') 2 | , test = require('tape') 3 | ; 4 | 5 | test('can get proc env vars',function(t){ 6 | var p = proc(process.pid); 7 | 8 | p.env(function(err,vars){ 9 | t.ok(!err,'should not have error getting args for this command'+err); 10 | t.ok(vars.length,"should have vars"); 11 | 12 | if(process.env.DEBUG) console.log(vars); 13 | 14 | t.end(); 15 | }); 16 | 17 | }) 18 | -------------------------------------------------------------------------------- /test/pid_stat.js: -------------------------------------------------------------------------------- 1 | var proc = require('../') 2 | , test = require('tape') 3 | ; 4 | 5 | test('can get prod info',function(t){ 6 | var p = proc(process.pid); 7 | 8 | p.stat(function(err,data){ 9 | t.ok(!err,'should not have error getting data for this pid '+err); 10 | t.ok(data,"should have data"); 11 | 12 | if(process.env.DEBUG) console.log(data); 13 | 14 | t.end(); 15 | }); 16 | 17 | }) 18 | -------------------------------------------------------------------------------- /test/pid_statm.js: -------------------------------------------------------------------------------- 1 | var proc = require('../') 2 | , test = require('tape') 3 | ; 4 | 5 | test('can get proc mem stat',function(t){ 6 | var p = proc(process.pid); 7 | 8 | p.statm(function(err,data){ 9 | t.ok(!err,'should not have error getting data for this pid '+err); 10 | t.ok(data,"should have data"); 11 | 12 | if(process.env.DEBUG) console.log(data); 13 | 14 | t.end(); 15 | }); 16 | 17 | }) 18 | -------------------------------------------------------------------------------- /test/pid_status.js: -------------------------------------------------------------------------------- 1 | var proc = require('../') 2 | , test = require('tape') 3 | ; 4 | 5 | test('can get proc status',function(t){ 6 | var p = proc(process.pid); 7 | 8 | p.status(function(err,data){ 9 | t.ok(!err,'should not have error getting data for this pid '+err); 10 | t.ok(data,"should have data"); 11 | 12 | if(process.env.DEBUG) console.log(data); 13 | 14 | t.end(); 15 | }); 16 | 17 | }) 18 | -------------------------------------------------------------------------------- /test/pid_threads.js: -------------------------------------------------------------------------------- 1 | var proc = require('../') 2 | , test = require('tape') 3 | ; 4 | 5 | test('can get proc threads',function(t){ 6 | var p = proc(process.pid); 7 | 8 | p.threads(function(err,threads){ 9 | t.ok(!err,'should not have error getting cwd for this process'+err); 10 | t.ok(threads.length,"should have threads"); 11 | 12 | if(process.env.DEBUG) console.log(threads); 13 | 14 | t.end(); 15 | }); 16 | 17 | }) 18 | -------------------------------------------------------------------------------- /test/tcp.js: -------------------------------------------------------------------------------- 1 | 2 | var test = require('tape'); 3 | var proc = require('../') 4 | 5 | test("can read tcp table",function(t){ 6 | proc.tcp(function(err,data){ 7 | if(process.env.DEBUG) console.log(data); 8 | t.ok(!err,'should not have error getting tcp info '+err); 9 | t.ok(data[0].local_address,'should have tcp data'); 10 | t.end(); 11 | }) 12 | }); 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/udp.js: -------------------------------------------------------------------------------- 1 | 2 | var test = require('tape'); 3 | var proc = require('../') 4 | 5 | test("can read udp table",function(t){ 6 | proc.udp(function(err,data){ 7 | if(process.env.DEBUG) console.log(data); 8 | t.ok(!err,'should not have error getting udp info '+err); 9 | t.ok(data[0].local_address,'should have udp data'); 10 | t.end(); 11 | }) 12 | }); 13 | -------------------------------------------------------------------------------- /test/unix.js: -------------------------------------------------------------------------------- 1 | var test = require('tape'); 2 | var proc = require('../'); 3 | 4 | test("can get active unix sockets",function(t){ 5 | proc.unix(function(err,data){ 6 | if(process.env.DEBUG) console.log(data); 7 | t.ok(!err,'should not have error '+err); 8 | t.ok(data[0].Inode,'should have Inode key if parsed correctly') 9 | t.end(); 10 | }); 11 | }) 12 | 13 | 14 | --------------------------------------------------------------------------------