Handle SIGCHLD
parent
72d8749454
commit
8128edc7eb
22
chat.c
22
chat.c
|
@ -22,6 +22,8 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -141,6 +143,7 @@ int main(int argc, char *argv[]) {
|
||||||
signal(SIGHUP, signalHandler);
|
signal(SIGHUP, signalHandler);
|
||||||
signal(SIGINT, signalHandler);
|
signal(SIGINT, signalHandler);
|
||||||
signal(SIGTERM, signalHandler);
|
signal(SIGTERM, signalHandler);
|
||||||
|
signal(SIGCHLD, signalHandler);
|
||||||
sig_t cursesWinch = signal(SIGWINCH, signalHandler);
|
sig_t cursesWinch = signal(SIGWINCH, signalHandler);
|
||||||
|
|
||||||
struct pollfd fds[2] = {
|
struct pollfd fds[2] = {
|
||||||
|
@ -155,6 +158,25 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
if (signals[SIGHUP]) self.quit = "zzz";
|
if (signals[SIGHUP]) self.quit = "zzz";
|
||||||
if (signals[SIGINT] || signals[SIGTERM]) break;
|
if (signals[SIGINT] || signals[SIGTERM]) break;
|
||||||
|
|
||||||
|
if (signals[SIGCHLD]) {
|
||||||
|
int status;
|
||||||
|
while (0 < waitpid(-1, &status, WNOHANG)) {
|
||||||
|
if (WIFEXITED(status) && WEXITSTATUS(status)) {
|
||||||
|
uiFormat(
|
||||||
|
Network, Warm, NULL,
|
||||||
|
"Process exits with status %d", WEXITSTATUS(status)
|
||||||
|
);
|
||||||
|
} else if (WIFSIGNALED(status)) {
|
||||||
|
uiFormat(
|
||||||
|
Network, Warm, NULL,
|
||||||
|
"Process terminates from %s",
|
||||||
|
strsignal(WTERMSIG(status))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (signals[SIGWINCH]) {
|
if (signals[SIGWINCH]) {
|
||||||
signals[SIGWINCH] = 0;
|
signals[SIGWINCH] = 0;
|
||||||
cursesWinch(SIGWINCH);
|
cursesWinch(SIGWINCH);
|
||||||
|
|
Loading…
Reference in New Issue