我知道可以使用活动监视器来检查进程是否正在通过 Apple Silicon 上的 Rosetta 运行。我想知道是否有办法对终端执行相同的操作?
编辑:
该进程是其他应用程序,因此如果有办法检查该进程是否在 Rosetta 中运行,则可能的命令可能具有以下语法:
$ is_running_under_rosetta <pid>
这会输出
yes
或者no
。
在安装了32位python 2.7的64位系统中,我尝试执行以下操作:
import subprocess
p = subprocess.call('dir', shell=True)
print p
Run Code Online (Sandbox Code Playgroud)
但这给了我:
Traceback (most recent call last):
File "test.py", line 2, in <module>
p = subprocess.call('dir', shell=True)
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)
如果我在终端做...
dir
Run Code Online (Sandbox Code Playgroud)
...当然会打印当前文件夹内容.
我试图将shell参数更改为shell = False.
编辑:其实我不能在路径上调用任何可执行文件subprocess.call()
.该声明p = subprocess.call('dir', shell=True)
在另一台机器上工作正常,我认为它是相关的.
如果我做
subprocess.call('PATH', shell=True)
Run Code Online (Sandbox Code Playgroud)
然后我明白了
Traceback (most …
Run Code Online (Sandbox Code Playgroud) 在macOS上使用线程清理程序运行时,以下代码会产生警告。我看不到比赛在哪里。shared_ptr和weak_ptr的控制块是线程安全的,并且std::queue
通过保持锁定来完成从中推入和弹出操作。
#include <future>
#include <memory>
#include <queue>
class Foo {
public:
Foo() {
fut = std::async(std::launch::async, [this] {
while (!shouldStop) {
std::scoped_lock lock(mut);
while (!requests.empty()) {
std::weak_ptr<float> requestData = requests.front();
requests.pop();
(void)requestData;
}
}
});
}
~Foo() {
shouldStop.store(true);
fut.get();
}
void add(const std::weak_ptr<float> subscriber) {
std::scoped_lock lock(mut);
requests.push(subscriber);
}
private:
std::atomic<bool> shouldStop = false;
std::future<void> fut;
std::queue<std::weak_ptr<float>> requests;
std::mutex mut;
};
int main() {
Foo foo;
int numIterations = 100000;
while (--numIterations) {
auto subscriber = std::make_shared<float>(); …
Run Code Online (Sandbox Code Playgroud) 我想在一个 io_context 中运行服务并在另一个 io_context 中执行业务逻辑。但首先我想了解更多有关重新调度行为的信息,因此我编写了一些实验代码。这是我的第一个版本(不使用 boost::asio::bind_executor())
boost::asio::io_context context1;
boost::asio::io_context context2;
// for simplicity I use post here, it will be socket operation in real code
boost::asio::post(context1, [&context2]()
{ boost::asio::post(context2, []() { printf("job finished"); }); });
// notice I didn't run context1 here
context2.run();
Run Code Online (Sandbox Code Playgroud)
context1 未运行,在本例中没有作业发布到 context2。所以 context2.run() 立即返回。当然,屏幕上没有打印任何内容。
然后这是使用 boost::asio::bind_executor() 的第二个版本
boost::asio::io_context context1;
boost::asio::io_context context2;
boost::asio::post(context1, boost::asio::bind_executor(context2, []()
{ printf("job finished"); }));
// notice I didn't run context1 here
context2.run();
Run Code Online (Sandbox Code Playgroud)
在这种情况下,进程永远停留在 context2.run() 中,等待待处理的作业被交付。
因此手写的包装器代码和 boost::asio::bind_executor() 的行为不同。这是错误还是故意的?建议采用哪一种方式?
提前致谢
例如,我可以std::vector
在 macOs/XCode 中的 DriverKit 驱动程序中使用吗?
DriverKit 有一些容器类,例如https://developer.apple.com/documentation/driverkit/osarray?language=objcOSArray
如果我创建一个新的“DriverKit 驱动程序”项目并包含,<vector>
那么我会收到构建错误。这些错误来自包含<cstring>
,错误是
No member named 'strcpy' in the global namespace
No member named 'strcat' in the global namespace
stl macos-catalina macos-system-extension driverkit xcode11.4
我不确定如何com.apple.developer.driverkit.transport.usb
在我的 dext 权利文件中设置密钥。Info.plist 文件已经包含该IOKitPersonalities
字典,并且阅读该com.apple.developer.driverkit.transport.usb
字典后,它看起来应该包含与 的条目具有相同信息的条目IOKitPersonalities
。
项目的权利文件与WWDC 驱动程序套件视频中显示的内容非常相似,将其设置为:
<key>com.apple.developer.driverkit.transport.usb</key>
<true/>
Run Code Online (Sandbox Code Playgroud)
当我将其设置为 时<true/>
,系统扩展启动。在看到应用程序的日志行之前,我确实看到了这样的一些行:
...
2020-05-06 12:23:19.229709+0200 0x51ac2 Default 0x0 0 0 kernel: DK: IOUserServer(sc.example.MyUserUSBInterfaceDriver-0x100002aad)::exit(CDHash check failed)
Run Code Online (Sandbox Code Playgroud)
这个权利应该只反映字典中的内容吗IOKitPersonalities
?
钥匙完全拔掉后,我得到:
...
2020-05-06 12:23:19.229709+0200 0x51ac2 Default 0x0 0 0 kernel: DK: IOUserServer(sc.example.MyUserUSBInterfaceDriver-0x100002aad)::exit(CDHash check failed)
2020-05-06 12:23:19.253517+0200 0x51ac2 Default 0x0 0 0 kernel: DK: IOUserServer(sc.example.MyUserUSBInterfaceDriver-0x100002aae)::exit(Entitlements check failed)
Run Code Online (Sandbox Code Playgroud)
..所以我想钥匙一定在那里。
我正在查看与应用程序相关的日志行log stream --source | grep MyUserUSBInterfaceDriver
我正在尝试与应用程序中的 ext 进行交互。我可以找到使用的服务,IOServiceOpen
并且可以调用NewUserClient
我的 dext(我可以看到type
传递的参数在日志中输出)。在此之后我有点失落。阅读此处有关NewUserClient的内容 ,我可以看到应该使用它Create
来创建一个新的 Service 对象。
这里的讨论部分说字典中的键propertiesKey
描述了新服务。
是否应该将此字典作为顶级条目放置在系统扩展的 plist 文件中,还是应该将字典放在 key 中IOKitPersonalities
?
我可以将IOServiceDEXTEntitlements
密钥保留为空值,以便不对连接到系统扩展的应用程序施加任何权利限制吗?
我的 plist 看起来像这样(键MyUserClientProperties
/字典在两个地方)。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>MyUserClientProperties</key>
<dict>
<key>IOClass</key>
<string>MyUserClient</string>
<key>IOUserClass</key>
<string>MyUserUSBInterfaceDriver</string>
<key>IOServiceDEXTEntitlements</key>
<string></string>
</dict>
<key>IOKitPersonalities</key>
<dict>
<key>example_device</key>
<dict>
<key>MyUserClientProperties</key> …
Run Code Online (Sandbox Code Playgroud) 我已在应用程序中分配内存并将其指针和大小传递给 IOConnectCallStructMethod
. 然后,IOMemoryDescriptor::CreateMapping
我已将此内存映射到 DriverKit 系统扩展进程,并且可以写入此映射的内存位置并从我的应用程序读取数据。
我现在想对系统扩展中分配的内存执行类似的操作,然后将其映射到使用系统扩展的应用程序。我想在系统扩展中创建一组内存缓冲区,然后从应用程序写入它,然后向系统扩展发出信号,告知给IOConnectCallScalarMethod
定的缓冲区应发送到 USB 设备,使用IOUSBHostPipe::AsyncIO
. 当CompleteAsyncIO
发送完成后出现回调时,我会通知应用程序现在可以将数据复制到发送的第一个缓冲区。此机制可能可以使用IOConnectCallAsyncStructMethod
和OSAction
在系统扩展中创建的对象来完成。我不明白的是如何将系统扩展中分配的内存映射到应用程序。
c++ ×4
driverkit ×4
iokit ×3
boost ×1
boost-asio ×1
entitlements ×1
path ×1
python ×1
python-2.7 ×1
rosetta ×1
shared-ptr ×1
shell ×1
stl ×1
subprocess ×1
usb ×1
weak-ptr ×1
xcode11.4 ×1