怎样判断一个进程是否死进程(100分)

  • 主题发起人 主题发起人 heiniu
  • 开始时间 开始时间
等待。。。。。。
 
上述问题可以转换成怎样判断一个主线程是否为死线程。方法有很多种,
比如说用事件。
 
用SendMessageTimeOut给那个进程发消息, 如果TimeOut了则说明死了
 
操作系统对不响应的进程也是采取发消息给它,如果超时就时死了,有API可以用,你自己
到WIN SDK中搜就找到了
 
The SendMessageTimeout function sends the specified message to a window
or windows. The function calls the window procedure for the specified window
and, if the specified window belongs to a different thread,do
es not return
until the window procedure has processed the message or the specified
time-out period has elapsed. If the window receiving the message belongs to
the same queue as the current thread, the window procedure is called directly ?
the time-out value is ignored.
LRESULT SendMessageTimeout(
HWND hWnd, // handle of destination window
UINT Msg, // message to send
WPARAM wParam, // first message parameter
LPARAM lParam, // second message parameter
UINT fuFlags, // how to send the message
UINT uTimeout, // time-out duration
LPDWORD lpdwResult // return value for synchronous call
);

Parameters
hWnd
Identifies the window whose window procedure will receive the message.
If this parameter is HWND_TOPMOST, the message is sent to all top-level windows
in the system, including disabled or invisible unowned windows.
Msg
Specifies the message to be sent.
wParam
Specifies additional message-specific information.
lParam
Specifies additional message-specific information.
fuFlags
Specifies how to send the message. This parameter can be a combination of
the following values:
Value Meaning
SMTO_ABORTIFHUNG Returns without waiting for the time-out period to elapse if the receiving process appears to be in a "hung" state.
SMTO_BLOCK Prevents the calling thread from processing any other requests until the function returns.
SMTO_NORMAL The calling thread is not prevented from processing other requests while waiting for the function to return.

uTimeout
Specifies the duration, in milliseconds, of the time-out period.
lpdwResult
Specifies the result of the message processing and depends on the message sent.

Return Values
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE.
顺手帖一下帮助的内容。
留意fuFlags参数的SMTO_ABORTIFHUNG标志,意味着接受进程一旦
挂起,不用等待超时就立即返回。
 
后退
顶部