2010-03-02 68 views
3

我正在尋找一種方式來如何以編程方式識別無響應(不是殭屍)進程。我發現一些信息來檢查TH_STATE_UNINTERRUPTIBLE狀態,但有一些討論認爲這不是正確的方法。有任何想法嗎?如何以編程方式識別沒有響應的進程

回答

1

我假設你的意思是一個旋轉輪應用程序掛起?有很多方法可以凍結。具體原因很重要。如果它是一個可可應用程序,你可以嘗試發送你的主線程/窗口事件...或腳本的自旋控制。

+0

您好, 感謝您的回覆。不幸的是,我試圖監控的過程不是我的應用程序,而是一個商業化的Java應用程序。它有時會佔用整個CPU並停止接受連接。我的想法是監視它,當它停止響應重新啓動它。 – BobC 2010-03-02 19:57:56

+0

在這種情況下,您是否可以安排後臺進程來打開連接並「ping」服務器?可能還會啓動帶有ulimit的Java應用程序,以便它在儲存時不會使CPU飽和。 – pestilence669 2010-03-03 00:30:25

1

隨機答案......我不是一個程序員,但我碰到可能感興趣的東西絆倒了,而通過的東西,在提出不同的工作......

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沒有類似的塊。

相關問題