[英]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. 我试图找到如何检查锁定的共享内存,即使用shmctl(SHM_LOCK)
,我发现我们可以通过检查shmid_ds.shmperm.mode标志在代码中检查它。
Now, like with mlock()
, we can check how much memory is being used by checking the /proc/<PID>/status
and the VmLck
value. 现在,与mlock()
,我们可以通过检查/proc/<PID>/status
和VmLck
值来检查正在使用多少内存。
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)
? 我想知道是否有任何方法可以检查使用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)
. 我已经尝试使用mlock
函数,它确实显示了使用了多少内存但是如果我使用shmctl(SHM_LOCK)
它会显示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). 只是添加,我想在shell中或通过代码看到锁定的内存(没有区别)。 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(1)命令,如下所示:
ipcs | grep locked
The ipcs command show the 'locked' status on the 'status' field, as shown by the ipcs.c code: ipcs命令在'status'字段中显示'locked'状态,如ipcs.c代码所示:
printf (" %-10ju %-6s %-6s\n",
shmdsp->shm_nattch,
shmdsp->shm_perm.mode & SHM_DEST ? _("dest") : " ", shmdsp->shm_perm.mode & SHM_LOCKED ? _("locked") : " ");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.