How to list processes attached to a shared memory segment in Linux?__linux

Source: Internet
Author: User

This article is organized from the Network, reference page (references): http://stackoverflow.com/questions/5658568/ How-to-list-processes-attached-to-a-shared-memory-segment-in-linux http://publib.boulder.ibm.com/infocenter/ Iseries/v5r4/index.jsp?topic=%2frzahz%2fipcs.htm

[Question]:

How do I determine what process are attached to a shared memory segment?

awagner@tree:/home/awagner$ ipcs-m

------Shared Memory segments--------
key        shmid      owner      perms      bytes      nattch     status      
0x00000000 0          Root       777        102400     1                       
0x00000000 32769      Root       774         1          dest         
0x00000000 98306      awagner     2          dest         
0x00000000 131075     awagner        393216     2          dest    

i.e. how did I figure out which two processes are attached to segment 98305?

[Answer]:

I don ' t have the standard tools. You can use the process ID of thelast process to Attach/detach but I ' m not aware of IPCS-MP D processes with IPCS.

With a two-process-attached segment, assuming they both stayed-attached, you can possibly figure out of the creator PID Cpid and last-attached PID lpid which are "two processes but that won" T scale to-more than two-so its processes The ESS is limited.

The Cat/proc/sysvipc/shm method seems similarly limited but I believe there ' s a way to do it with other parts of The/pro c filesystem, as shown below:

When I does a grep on the PROCFS maps to all processes, I get entries containing lines for the Cpidand lpid.

For example, I get the following shared memory segment from IPCS-M:

------Shared Memory Segments--------
key        shmid      owner      perms      bytes      nattch     status      
0x00000000 123456     pax        1024       2          dest

And, from IPCS-MP, the cpid are 3956 and the lpid is 9999 to that given shared memory segment (123456).

Then, with the command grep 123456/proc/*/maps, I:

/proc/3956/maps:blah blah blah 123456/sysv000000 (deleted)/proc/9999/maps:blah blah blah 123456/sysv000000
(dele Ted

So there are a way to get the processes which attached to it. I m pretty certain that dest status and (deleted) indicator are because the creator has marked the segment for destruct Ion once the final detach occurs, not that it ' s already been.

So, by scanning of the/proc/*/maps ' files ', you are should be able to discover-which PIDs are currently to a attached s Egment.

Cpid (-P,-a) The process ID of the job that created the shared memory segment.

Lpid (-P,-a) The process ID of the last job to attach or detach from the shared memory segment or change the semaphore value.

Related Article

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.