umayneverknow
umayneverknow

Reputation: 190

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, i.e, 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.

Upvotes: 4

Views: 3969

Answers (1)

Breno Leit&#227;o
Breno Leit&#227;o

Reputation: 3677

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") : " ");

Upvotes: 2

Related Questions