/* * Copyright (C) 2004 Aleksandar Colovic * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ #include #include #include #include #include #include #include #include using namespace std; void handler (int nSignalNo) { cout << "Signal SIGUSR1 received by thread: " << pthread_self() << endl; } void* doWork(void* pArg) { cout << "Worker thread (" << pthread_self() << ") doing the job!" << endl; sleep(5); return 0; } int main (int argc, char* const argv[]) { struct sigaction sa; memset (&sa, 0, sizeof (sa)); sa.sa_handler = &handler; sigaction (SIGUSR1, &sa, 0); pthread_t hThread; pthread_create(&hThread, 0, &doWork, 0); sigset_t signal_mask; sigemptyset (&signal_mask); sigaddset (&signal_mask, SIGUSR1); pthread_sigmask (SIG_BLOCK, &signal_mask, 0); cout << "Main thread (" << pthread_self() << ") sending SIGUSR1 to the process!" << endl; kill(getpid(), SIGUSR1); pthread_join(hThread, 0); return 0; };