1
所以我必须实施沙箱功能才能将我的Mac应用保留在Mac应用商店中。当我启用沙箱时,我的应用程序大部分工作。我使用“top”命令获取整个用户系统的CPU信息和RAM信息。随着沙箱,我不再有权访问这些功能。这是收到的运行时错误:沙箱问题
/bin/sh: /usr/bin/top: Operation not permitted
/bin/sh: /usr/bin/top: Operation not permitted
2012-05-29 20:40:57.911 QuickToggles[53714:403] *** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]
2012-05-29 20:40:57.928 QuickToggles[53714:403] (
0 CoreFoundation 0x00007fff986bcf56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff97f98d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff98666370 -[__NSArrayI objectAtIndex:] + 208
3 QuickToggles 0x0000000100001961 -[StatusBarAppAppDelegate updateInfo:] + 177
4 Foundation 0x00007fff94666f40 __NSFireTimer + 102
5 CoreFoundation 0x00007fff98671934 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
6 CoreFoundation 0x00007fff98671486 __CFRunLoopDoTimer + 534
7 CoreFoundation 0x00007fff98651e11 __CFRunLoopRun + 1617
8 CoreFoundation 0x00007fff98651486 CFRunLoopRunSpecific + 230
9 HIToolbox 0x00007fff9806b4d3 RunCurrentEventLoopInMode + 277
10 HIToolbox 0x00007fff980726d3 ReceiveNextEventCommon + 181
11 HIToolbox 0x00007fff9807260e BlockUntilNextEventMatchingListInMode + 62
12 AppKit 0x00007fff90441e31 _DPSNextEvent + 659
13 AppKit 0x00007fff90441735 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
14 AppKit 0x00007fff9043e071 -[NSApplication run] + 470
15 AppKit 0x00007fff906ba244 NSApplicationMain + 867
16 QuickToggles 0x0000000100001882 main + 34
17 QuickToggles 0x0000000100001854 start + 52
18 ??? 0x0000000000000003 0x0 + 3
)
您的平台是否提供'getrusage()'函数?它提供了你需要的细节吗? (解析'top'首先感觉就像是发现这些信息的总体方式,但那只是我..) – sarnold
当然这不起作用; top尝试获取有关系统中每个进程的信息,这显然不允许在您的沙盒中。 @sarnold:是的,有getrusage,包括RUSAGE_CHILDREN(如果他的应用程序产生一堆子进程,这很重要)。 – abarnert
我的应用程序不会获取应用程序本身的资源使用情况,但可以获取整个计算机的资源使用情况。解析顶部是我看到以简单清晰的方式获取统计信息的最简单方法。 –