How can we check the "locked" shared process memory in Linux?

I tried to find how to check for locked shared memory, i.e. using shmctl(SHM_LOCK), and I found that we can check it in code by setting the shmid_ds.shmperm.mode flag.

Now, similarly mlock(), we can check how much memory is being used by checking the value of /proc/<PID>/statusand VmLck.

I would like to know if there is a way to check how much shared memory is being used by a process that has been locked with shmctl(SHM_LOCK)?

I tried to use a function mlockand it shows how much memory is used, but it shows 0kb if I use shmctl(SHM_LOCK).

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

I tried to browse the forum, but could not find the answer to this question. Any help is appreciated.

+3
source share
1 answer

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

ipcs | grep locked

The ipcs command displays the status "blocked" in 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") : " ");
+1
source

All Articles