Socket programming problems
Sigpipe signal problem ============================
When the server closes a connection, if the client sends data. According to the TCP protocol, an rst response is received. When the client sends data to the server, the system sends a sigpipe signal to the process, telling the process that the connection has been disconnected, do not write any more.
According to the default signal processing rules, the default operation of the sigpipe signal is terminate (termination, exit), so the client will exit. If you do not want the client to exit, set sigpipe to sig_ign.
For example, signal (sigpipe, sig_ign );
At this time, sigpipe is handed over to the system for processing.
If fork is used on the server, it is necessary to collect the garbage process to prevent the generation of the zombie process. You can handle it like this:
Signal (sigchld, sig_ign); hand it to the system init for recycling.
Here, sub-processes will not generate zombie processes.
Another processing method: sigpipe Signal Processing
Signal (sigpipe, handle_omsignal );
Void handle_omsignal (
Int number)
{
Switch (number)
{
Default:
{
Break;
}
Case sigpipe:
{
Om_alog (error, "omagentd", "% s", "network error! ");
Break;
}
}
}
Of course, this will not happen if the client is not connected to the server.
========================================================== ==========
Processes and threads
: A thread is an execution process of a process. multiple threads run on the process's Resource Platform. If the process is dead, the thread will die.
Socket programming problems
Sigpipe signal problem ============================
When the server closes a connection, if the client sends data. According to the TCP protocol, an rst response is received. When the client sends data to the server, the system sends a sigpipe signal to the process, telling the process that the connection has been disconnected, do not write any more.
According to the default signal processing rules, the default operation of the sigpipe signal is terminate (termination, exit), so the client will exit. If you do not want the client to exit, set sigpipe to sig_ign.
For example, signal (sigpipe, sig_ign );
At this time, sigpipe is handed over to the system for processing.
If fork is used on the server, it is necessary to collect the garbage process to prevent the generation of the zombie process. You can handle it like this:
Signal (sigchld, sig_ign); hand it to the system init for recycling.
Here, sub-processes will not generate zombie processes.
Another processing method: sigpipe Signal Processing
Signal (sigpipe, handle_omsignal );
Void handle_omsignal (
Int number)
{
Switch (number)
{
Default:
{
Break;
}
Case sigpipe:
{
Om_alog (error, "omagentd", "% s", "network error! ");
Break;
}
}
}
Of course, this will not happen if the client is not connected to the server.
========================================================== ==========
Processes and threads
: A thread is an execution process of a process. multiple threads run on the process's Resource Platform. If the process is dead, the thread will die.