我很新開發使用xcode的mac osx應用程序。我試圖讓所有正在運行的應用程序列表的內存使用情況。 在這種情況下,任何機構都可以幫助我。Mac OSX - 獲取所有正在運行的應用程序列表以及內存使用情況
請幫幫我。
在此先感謝。
我很新開發使用xcode的mac osx應用程序。我試圖讓所有正在運行的應用程序列表的內存使用情況。 在這種情況下,任何機構都可以幫助我。Mac OSX - 獲取所有正在運行的應用程序列表以及內存使用情況
請幫幫我。
在此先感謝。
它會幫助你得到運行的應用程序的列表:
for (NSRunningApplication *app in [[NSWorkspace sharedWorkspace] runningApplications]) {
NSLog(@"%@",[app localizedName]);
}
你可能會得到CPU的使用率:
- (NSString*) get_process_usage:(int) pid
{
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/ps"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"-O",@"%cpu",@"-p",[NSString stringWithFormat:@"%d",pid], nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSString* temp = [string stringByReplacingOccurrencesOfString:@"PID %CPU TT STAT TIME COMMAND" withString:@""];
NSMutableArray* arr =(NSMutableArray*) [temp componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[arr removeObject:@""];
[string release];
[task release];
if([arr count]>=2)
return [arr objectAtIndex:1];
else
return @"unknown";
}
它無法在Mac App Store上提交,請選擇其他解決方案。 –
它不在沙箱環境中工作....沒有沙箱,它工作正常 –
@dhanshree&shardul .....分享你的知識謝謝並更新我。 – kashinath