#include #include #include #include #include #include /* Simple error handling functions */ #define handle_error_en(en, msg) \ do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) int main(int ac, char *av[]) { sigset_t set; int i; char buff[512]; (void)puts("#start"); sigemptyset(&set); sigaddset(&set, SIGRTMIN+2); sigaddset(&set, SIGRTMIN+3); i = pthread_sigmask(SIG_BLOCK, &set, NULL); if (i != 0) handle_error_en(i, "pthread_sigmask() failed"); (void)puts("#mark1"); /* * stupid /bin/kill in Linux cannot handle realtime signal * *names*, so we pass the signal number instead */ (void)snprintf(buff, sizeof(buff), "kill -s %d %ld", (int)SIGRTMIN+2, (long)getpid()); (void)printf("# executing '%s'\n", buff); (void)system(buff); (void)puts("#mark2"); (void)sleep(2); (void)puts("#mark3"); i = pthread_sigmask(SIG_UNBLOCK, &set, NULL); if (i != 0) handle_error_en(i, "pthread_sigmask() failed"); /* * unblocking the SIGRTMIN signals will trigger the default handler for * the SIGRT signals, which terminates the process, so we will never reach * this point in the program */ (void)puts("#notreached"); return EXIT_SUCCESS; }