Created
February 13, 2018 21:34
-
-
Save yuikns/6ae8aaec8f1c89e1ee6eb87e36a8639a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "argcv/c/sys/signal.h" | |
#include <sys/types.h> // pid_t | |
#include <stdio.h> // printf | |
#include <signal.h> // signal | |
#include <sys/wait.h> // wait | |
sigfunc* _signal(int signo, sigfunc* func) { | |
struct sigaction act; // bits/sigaction.h | |
struct sigaction oact; | |
printf("signal called ...\n"); | |
act.sa_handler = func; | |
sigemptyset(&act.sa_mask); // signal.h | |
act.sa_flags = 0; | |
if (signo == SIGALRM) { | |
#ifdef SA_INTERRUPT | |
act.sa_flags |= SA_INTERRUPT; // SunOS 4.x | |
#endif // SA_INTERRUPT | |
} else { | |
#ifdef SA_RESTART | |
act.sa_flags |= SA_RESTART; // SVR4, 4.4BSD | |
#endif // SA_RESTART | |
} | |
if (sigaction(signo, &act, &oact) < 0) return SIG_ERR; | |
return oact.sa_handler; | |
} | |
/** | |
* | |
*/ | |
void sig_chld(int signo) { | |
pid_t pid; | |
int stat; | |
while ((pid = waitpid(-1, &stat, WNOHANG)) > 0) { | |
// #ifdef __DEBUG__ | |
// if (daemon_proc) { | |
// syslog(LOG_DEBUG, "child %d terminated \n", pid); | |
// } else { | |
// fprintf(stdout, "child %d terminated \n", pid); | |
// } | |
// #endif // __DEBUG__ | |
} | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef ARGCV_C_SYS_SIGNAL_H_ | |
#define ARGCV_C_SYS_SIGNAL_H_ | |
#ifdef __cplusplus | |
extern "C" { | |
#endif // | |
// ref P. 105 , unix network programming | |
// ref : https://docs.oracle.com/cd/E19455-01/806-4750/signals-7/index.html | |
typedef void sigfunc(int); | |
sigfunc* _signal(int signo, sigfunc* func); | |
void sig_chld(int signo); | |
#ifdef __cplusplus | |
} | |
#endif // | |
#endif // ARGCV_C_SYS_SIGNAL_H_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment