管理共享内存在C对OSX [英] Managing Shared Memory in C on OSX

查看:382
本文介绍了管理共享内存在C对OSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一所大学的任务,很大程度上左右IPC和共享内存。问题是,作为一个完整的小白到C,我已经高兴地测试我的应用程序(它使用 shmget的的shmat 显然)几个小时。正如你可能已经猜到了,我还没有得到照顾自己清理了,现在我不能运行我的应用程序,因为(我假设) shmget的不能再分配资源。

I am working on a university assignment, based largely around IPC and shared memory. The problem is, as a complete noob to C, I've been happily testing my app (which uses shmget and shmat obviously) for hours. As you can probably guess, I've not been cleaning up after myself, and now I can't run my app, because (I assume) shmget cant allocate anymore resources.

我的问题是:我怎么能得到这个资源重新无需重新启动OSX,而​​且是有一个GUI工具,或者是我可以用它来监控/管理这种共享内存的我创建

My question is: how can I get this resource back without restarting OSX, and is there a GUI tool or something I can use to monitor/manage this shared memory I am creating?

推荐答案

shmdt 在每个持有对它的引用过程中的共享内存段(共享内存分离)。 Unix的共享内存部分是引用计数的,所以当最后一个进程从中分离,它们可以使用的 了shmctl(ID,IPC_RMID,NULL)

从您的应用程序之外,我能想到的,现在唯一的选择来清除共享内存段是:

From outside your application, the only option I can think of right now to clear your shared memory segments is:

for (int id=0; id < INT_MAX; id++)
    shmctl(id, IPC_RMID, NULL);

但是这是一个可怕的低效的杂牌。 (我也不能肯定它是否工作;它不会在Linux,但Linux侵犯Unix的标准,而MacOS X系统是反对它的认证。)

but this is a horribly inefficient kludge. (I'm also not sure if it works; it doesn't on Linux, but Linux violates the Unix standard while MacOS X is certified against it.)

这篇关于管理共享内存在C对OSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆