简体   繁体   中英

How do we check the “locked” shared memory of a process in linux?

I was trying to find how to check whether the locked shared memory, ie, using shmctl(SHM_LOCK) and I found that we can check it in the code by checking the shmid_ds.shmperm.mode flag.

Now, like with mlock() , we can check how much memory is being used by checking the /proc/<PID>/status and the VmLck value.

I would like to know if there is any way of checking how much shared memory is being used by a process that was locked using shmctl(SHM_LOCK) ?

I have tried using the mlock function and it does show how much memory is used but it shows 0kb if I use shmctl(SHM_LOCK) .

Just to add, I'd like to see the locked memory in the shell or through code (doesn't make a difference). I just need a value.

Tried looking through the forum but couldn't find any answer to this. Any help is appreciated.

You should use the ipcs(1) command, as:

ipcs | grep locked

The ipcs command show the 'locked' status on the 'status' field, as shown by the ipcs.c code:

        printf (" %-10ju %-6s %-6s\n",
                  shmdsp->shm_nattch,
                  shmdsp->shm_perm.mode & SHM_DEST ? _("dest") : " ",                    shmdsp->shm_perm.mode & SHM_LOCKED ? _("locked") : " ");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM