Detection of framework usage on Mac system?

老子叫甜甜 提交于 2019-12-13 16:07:05

问题


I wanted to develop sample framework on OSX with having requirement that at any point in time the framework should be used by only single client, i am not getting how to achieve this ? is their any API's to detect weather the framework is in use? can we use some file related API for this?..i have seen a windows sample where they where detecting the dylib's usage using Following API's ?? CreateFileMappingW MapViewOfFile OpenFileMappingW

Does anyone has come across such scenarios??


回答1:


You can use lsof command. it will return list of open files.

In the absence of any options, lsof lists all open files belonging to all active processes.

NSTask* task = [[NSTask alloc] init];
NSPipe* pipe = [[NSPipe alloc] init];

NSArray* args = [NSArray arrayWithObjects: @"-c", @"lsof | grep -i some.framework | wc -l",nil];
[task setLaunchPath: @"/bin/sh"];
[task setArguments: args];
[task setStandardOutput: pipe];
[task setStandardError: pipe];
[task setStandardInput: [NSPipe pipe]]; 
[task launch];    
[task waitUntilExit];

NSFileHandle* file = [pipe fileHandleForReading];
NSString* result = [[NSString alloc] initWithData: [file readDataToEndOfFile] encoding: NSASCIIStringEncoding];
NSLog(@"%@",result);
[result release];
[task release];
[pipe release];


来源:https://stackoverflow.com/questions/16667860/detection-of-framework-usage-on-mac-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!