Linux Program Analysis tool Introduction (i)--"/proc"

Source: Internet
Author: User

Written in the first: Before the beginning of this article, I think it is necessary to introduce the man under Linux, if the reader on hand with the Linux system, directly in the terminal input Man man can see the detailed instructions, I am here to summarize briefly, the Man command is used to view the various commands in Linux, User manual for Tools, etc. (manual). A more common usage is "man n field", where n is the type of manual to look for, field is the keyword. Here is a description of N:

    • Header file under 0/usr/include
    • 1 executable programs and shell commands
    • 2 system Calls
    • 3 System Library functions
    • Special files under the 4/dev
    • 5 File formats and conventions (e.g./etc/passwd)

    • 6 games
    • 7 Other
    • 8 only root-available system administration commands
    • 9 Kernel-related content

Usually, if you do not add N, the system will be in a certain order, sometimes the resulting may not be what you want, then you need to add N, this is what I want to introduce the purpose of N. For example, you man printf, the system returned must be the shell command printf, you want to see the library function printf What to do, then man 3 printf,that ' s OK
The following goes to today's point,/proc is a Linux system for our users can be used to access system-related data and information of a pseudo-file system, through which we can not only get to specify a process related information, but also to obtain the overall system operation and information. Because this article is about the tools of the parser, this article will focus on the analysis of the program itself through/proc, on how to view the system information through/PROC, can be seen through the man 5 proc (this is one of the reasons I started talking about man).

    • /proc/[number]/cmdline program command line arguments to ' \0′ delimited string file (in the program, you can read this file directly, get the command line parameters of the program, but it is not recommended to do so, so the program is not portable)
    • /PROC/[NUMBER]/CWD a soft link to the current working path of the program (Readlink can get the linked directory)
    • /proc/[number]/environ the current environment variable of the program to ' \0′ delimited string file
    • Soft link to the executable file of the/proc/[number]/exe program (the full path of the program executable can be obtained via Readlink)
    • /PROC/[NUMBER]/FD program is currently using FD, these FD are linked to the actual file
    • /proc/[number]/maps The address space distribution and access rights of the program (through which you can see if the address of the process is in a valid range)
12345678910
Address           perms offset  dev   inode      pathname08048000-08056000 R-xp 00000000 03:0c 64593      /usr/sbin/ gpm08056000-08058000 rw-p 0000d000 03:0c 64593      /usr/sbin/gpm08058000-0805b000 Rwxp 00000000 00:00 040000000-40013000 R-xp 00000000 03:0c 4165       /lib/ld-2.2.4.so40013000-40015000 rw-p 00012000 03:0c 4165       /lib/ ld-2.2.4.so4001f000-40135000 R-xp 00000000 03:0c 45494      /lib/libc-2.2.4.so40135000-4013e000 rw-p 00115000 03:0c 45494      /lib/libc-2.2.4.so4013e000-40142000 Rw-p 00000000 00:00 0bffff000-c0000000 Rwxp 00000000 00:00 0
    • Memory usage for each memory-mapped area of the/proc/[number]/smaps (since Linux 2.6.14) program
1234567
08048000-080bc000 R-xp 00000000 03:02 13130/bin/bash    #与maps中的相同Size:               464 kb                       #映射区的大小Rss:                424 KB                       # Actual in-memory size Shared_clean:       424 kB shared_dirty:         0 Kbprivate_clean:        0 Kbprivate_dirty:        0 kb
    • /proc/[number]/stat The status information of the program, the PS command gets the program information is obtained from here, so the detailed capacity can be PS command
    • Memory page State of the/PROC/[NUMBER]/STATM program
1234567
Size Total program       sizeresident   resident set Sizeshare      shared pagestext       text (code) Lib        Librarydata       Data/stackdt         dirty pages (unused in Linux 2.6)
    • /proc/[number]/status Stat and STATM together to show the
    in a more user-friendly way

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.