void MonitorParentProcess()
{
pid_t parentPID = getppid();
dispatch_queue_t queue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC,
parentPID, DISPATCH_PROC_EXIT,
queue);
if (source) {
dispatch_source_set_event_handler(source, ^{
MySetAppExitFlag();
dispatch_source_cancel(source);
dispatch_release(source);
});
dispatch_resume(source);
}
}
Monitoring the death of a parent process (via Dispatch Sources)
最新推荐文章于 2018-06-27 14:56:23 发布