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

问题描述:

我正在寻找一种方式来如何以编程方式识别无响应(不是僵尸)进程。我发现一些信息来检查TH_STATE_UNINTERRUPTIBLE状态,但有一些讨论认为这不是正确的方法。有任何想法吗?如何以编程方式识别没有响应的进程

我假设你的意思是一个旋转轮应用程序挂起?有很多方法可以冻结。具体原因很重要。如果它是一个可可应用程序,你可以尝试发送你的主线程/窗口事件...或脚本的自旋控制。

+0

您好, 感谢您的回复。不幸的是,我试图监控的过程不是我的应用程序,而是一个商业化的Java应用程序。它有时会占用整个CPU并停止接受连接。我的想法是监视它,当它停止响应重新启动它。 – BobC 2010-03-02 19:57:56

+0

在这种情况下,您是否可以安排后台进程来打开连接并“ping”服务器?可能还会启动带有ulimit的Java应用程序,以便它在储存时不会使CPU饱和。 – pestilence669 2010-03-03 00:30:25

随机答案......我不是一个程序员,但我碰到可能感兴趣的东西绊倒了,而通过的东西,在提出不同的工作......

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. 
*/ 

- 是的,关于卡住的线程,想不到?

还是从关于进程的问题太过分吗?


一目了然,代码在sched_prim.c in xnu-1699.26.8源的Mac OS X 10.7.4没有类似的块。