Monitoring the death of a parent process (via Dispatch Sources)

来源:互联网 发布:淘宝买家怎么变成卖家 编辑:程序博客网 时间:2024/05/17 17:16
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);     }}

0 0