检测Mac系统上的框架使用情况? [英] Detection of framework usage on Mac system?

查看:106
本文介绍了检测Mac系统上的框架使用情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在OSX上开发示例框架,但要求在任何时候该框架仅应由单个客户端使用,而我没有得到如何实现此目标的条件?他们的API是否可以检测框架正在使用的天气?我们可以为此使用一些与文件相关的API吗?..我看到了一个Windows示例,其中使用
以下API来检测dylib的使用?
CreateFileMappingW
MapViewOfFile
OpenFileMappingW

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??

推荐答案

您可以使用 lsof 命令。它将返回打开文件的列表。

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


在没有任何选项的情况下,lsof会列出属于
所有活动进程的所有打开文件。

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];

这篇关于检测Mac系统上的框架使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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