应用程序退出事件

妖怪啊 2017-01-06 07:13:11
在C#中的Process类都会有个Exited事件,在Java语言中也有一个类似的事件

class TestProcess
{
public static void OnExited(object sender, EventArgs e)
{
/// exited event handle
}

public static void main()
{
Process p = Process.Start("cmd.exe");
p.Exited += OnExited;
}
}

请问在C/C++语言中,在windows和linux下分别如何监听进程的退出事件
还有如何判断一个进程是否退出

只有个30分了,还望大神解惑
...全文
356 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2017-01-12
  • 打赏
  • 举报
回复
《Windows核心编程》
ID870177103 2017-01-11
  • 打赏
  • 举报
回复
WaitForSingleObject不行吗
妖怪啊 2017-01-11
  • 打赏
  • 举报
回复
引用 1 楼 qq423399099 的回复:
http://blog.csdn.net/jmppok/article/details/16845627
引用 1 楼 qq423399099 的回复:
http://blog.csdn.net/jmppok/article/details/16845627
可能没有理解我的意思 我的意思是在进程A中创建进程B,当进程B正常或者异常’退出时,A进程可以获得通知 上面给的回答都是进程内的退出事件
赵4老师 2017-01-09
  • 打赏
  • 举报
回复
赵4老师 2017-01-09
  • 打赏
  • 举报
回复
atexit Processes the specified function at exit. int atexit( void ( __cdecl *func )( void ) ); Routine Required Header Compatibility atexit <stdlib.h> ANSI, Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version To generate an ANSI-compliant application, use the ANSI-standard atexit function (rather than the similar _onexit function). Return Value atexit returns 0 if successful, or a nonzero value if an error occurs. Parameter func Function to be called Remarks The atexit function is passed the address of a function (func) to be called when the program terminates normally. Successive calls to atexit create a register of functions that are executed in LIFO (last-in-first-out) order. The functions passed to atexit cannot take parameters. atexit and _onexit use the heap to hold the register of functions. Thus, the number of functions that can be registered is limited only by heap memory. Example /* ATEXIT.C: This program pushes four functions onto * the stack of functions to be executed when atexit * is called. When the program exits, these programs * are executed on a "last in, first out" basis. */ #include <stdlib.h> #include <stdio.h> void fn1( void ), fn2( void ), fn3( void ), fn4( void ); void main( void ) { atexit( fn1 ); atexit( fn2 ); atexit( fn3 ); atexit( fn4 ); printf( "This is executed first.\n" ); } void fn1() { printf( "next.\n" ); } void fn2() { printf( "executed " ); } void fn3() { printf( "is " ); } void fn4() { printf( "This " ); } Output This is executed first. This is executed next. Process and Environment Control Routines See Also abort, exit, _onexit

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧