如何以编程方式识别未响应的进程

时间:2010-03-02 19:43:16

标签: objective-c cocoa unix

我正在寻找一种如何以编程方式识别非响应(非僵尸)进程的方法。我找到一些信息来检查TH_STATE_UNINTERRUPTIBLE状态,但有一些讨论说这不是正确的方法。

2 个答案:

答案 0 :(得分:1)

我假设你的意思是纺车应用程序悬挂?有很多方法可以冻结。特别的原因很重要。如果它是一个Cocoa应用程序,你可以尝试发送你的主线程/ Window一个事件...或脚本编写Spin Control。

答案 1 :(得分:1)

一个随机的回答......我不是程序员,但我偶然发现了一些可能的兴趣,同时解决了Ask Different中的问题......

sched_prim.c(调度原语)in relatively old xnu-124.7包括:

#define MAX_STUCK_THREADS   128

/*
 *  do_thread_scan: scan for stuck threads.  A thread is stuck if
 *  it is runnable but its priority is so low that it has not
 *  run for several seconds.  Its priority should be higher, but
 *  won't be until it runs and calls update_priority.  The scanner
 *  finds these threads and does the updates.
 *
 *  Scanner runs in two passes.  Pass one squirrels likely
 *  thread ids away in an array  (takes out references for them).
 *  Pass two does the priority updates.  This is necessary because
 *  the run queue lock is required for the candidate scan, but
 *  cannot be held during updates [set_pri will deadlock].
 *
 *  Array length should be enough so that restart isn't necessary,
 *  but restart logic is included.  Does not scan processor runqs.
 *
 */
thread_t        stuck_threads[MAX_STUCK_THREADS];
int             stuck_count = 0;

/*
 *  do_runq_scan is the guts of pass 1.  It scans a runq for
 *  stuck threads.  A boolean is returned indicating whether
 *  a retry is needed.
 */

- 是关于卡住线程,值得深思的话?

还是关于进程的问题呢?


乍一看,Mac OS X 10.7.4的sched_prim.c in xnu-1699.26.8源代码中没有类似的代码块。