Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<pthread.h>
- #include<stdio.h>
- #include<signal.h>
- #include<unistd.h>
- void sig_handler(int signo)
- {
- printf("received SIGUSR1\n");
- _exit(0);
- }
- void *theOtherThread(void*) {
- while(true) {} // ∞ cycle
- }
- int main() {
- if (signal(SIGUSR1, sig_handler) == SIG_ERR)
- printf("\ncan't catch SIGUSR1\n");
- pthread_t thr;
- if (pthread_create(&thr, 0, theOtherThread, 0)) { // invoke a child thread
- perror("Creating thread");
- return 1;
- }
- sleep(1); // sleep one second
- pthread_kill(thr, SIGUSR1); // send signal to the child thread
- if (pthread_join(thr, 0)) { // wait for the child thread to exit
- perror("Creating thread");
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement