1、问题 linux 下socket 发送,当接收端关闭的时候,程序异常崩溃。
The inferior stopped because it received a signal from the operating system.
Signal name :SIGPIPE
Signal meaning :
Broken pipe
解决方案为:
只要在main函数一开始就写入上面这段代码,就能屏蔽掉pthread线程中的SIGPIPE
#include <signal.h>
sigset_t signal_mask;
sigemptyset (&signal_mask);
sigaddset (&signal_mask, SIGPIPE);
int rc = pthread_sigmask (SIG_BLOCK, &signal_mask, NULL);
if (rc != 0) {
printf("block sigpipe error/n");
}