Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9148661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:20:09+00:00 2026-06-17T11:20:09+00:00

I tried to get the shared memory size of a process on Linux. Here’s

  • 0

I tried to get the shared memory size of a process on Linux. Here’s the result of using 2 different commands:

  1. top and check with the SHR field:

     PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1734 root      20   0  201m 4072 1012 S  0.0  0.1  22:00.65 php-fpm
    
  2. pmap -d :

    mapped: 206672K    writeable/private: 4352K    shared: 128K
    

You can see that the shared memory size in pmap is much smaller than top.

I read some source code to find the reason. It seems that top is reading the value from /proc//statm and the values are calculated by:

unsigned long task_statm(struct mm_struct *mm,
    unsigned long *shared, unsigned long *text,
    unsigned long *data, unsigned long *resident)
{
    *shared = get_mm_counter(mm, MM_FILEPAGES);
    *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
                                                       >> PAGE_SHIFT;
    *data = mm->total_vm - mm->shared_vm;
    *resident = *shared + get_mm_counter(mm, MM_ANONPAGES);
    return mm->total_vm;
}

It seems that all the file pages are counted as shared memory?

And the pmap command is reading the info from /proc//maps and then calculate the shared memory through some flags:

3dc822a000-3dc822d000 rw-p 0002a000 08:13 5134288      /usr/lib64/libmcrypt.so.4.4.8
start-end flags file_offset dev_major:dev_minor inode

If the flags[3] == ‘s’ then this map will be counted as shared one.

So my question is which one is more accurate? And why they have different methods to calculate the shared memory size?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:20:11+00:00Added an answer on June 17, 2026 at 11:20 am

    The SHR column in top does not report the same thing that pmaps shared entry does. top is reporting the amount of memory that is shared with other processes because it’s in a dynamic library that is loaded once into memory, and all processes using that library include the same pages in their image, since those pages are read-only. pmap seems to be showing “shared memory” segments, which are data pages that may be read-write or read-only, and are shared between processes with the shmget() and related functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to allocate shared memory as a 2D array using IPC. I tried
I recently forked https://github.com/fortuity/rails3-mongoid-omniauth and tried to get login working for different providers. It
I'm in Linux 2.6. I have an environment where 2 processes simulate (using shared
I'm using System V Shared Memory to communicate between my two PHP applications. One
I have tried to get this working, looked at multiple tutorials, questions on here
I tried to get an answer from server and conver it to JSONObject .
i Tried to get data from excel in java. if i execute it as
I tried to get the SLDeviceVolumeItf interface of the RecorderObject on Android but I
I tried to get into pyglet and opengl and come up with weird results
I tried to get avatar at single (post) page by these codes <?php echo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.