子进程出现除0异常,父进程会咋样线程出现异常,所在的进程会咋样

一、父进程会收到 SIGCHLD 信号通知的。二、假设你的「M对N」指的是「M个用户级进程对应N个内核级线程」:man 7 sginal 有说\u0026gt; A signal may be generated (and thus pending) for a process as a whole (e.g.,\u0026gt; when sent using kill(2)) or for a specific thread (e.g., cer‐tain\u0026gt; signals, such as SIGSEGV and SIGFPE, generated as a consequence of\u0026gt; executing a specific machine-language instruction are thread directed, as are\u0026gt; signals targeted at a specific thread using pthread_kill(3)).\u0026gt; A process-directed signal may be delivered to any one of the threads that\u0026gt; does not currently have the signal blocked. If more than one of the threads\u0026gt; has the signal unblocked, then the kernel chooses an arbitrary thread to\u0026gt; which to deliver the signal.所以除零错的信号只会发送到触发此信号的内核级线程。至于用户级线程会怎么做,取决于该用户级线程的实现。
■网友
Windows下进程的机制我不太了解,所以无法回答。Linux下的进程线程机制略懂一二,只能尽我所能回答,如有误,欢迎指正。问题一:父进程如果没有wait或者waitpid,那么子进程就会成为孤儿进程,最后由系统的默认进程init接管,并做相应处理。具体可参考《Unix网络编程》或者《Unix环境高级编程》。问题二:恕我孤陋寡闻,多线程的模型指的是啥,完全没印象。
■网友
因为项目需要,写Java也写C++ 而且都设计到多线程,两个语言的不同会导致世界观错乱。子线程异常被抛出,C++会直接栈展开并terminate,让主线程也不要活了。Java则不会。


    推荐阅读