Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Zademonstruj działanie funkcji pthread kill() wysyłając do wątku sygnał, dla którego będzie on
- miał własną procedurę obsługi. Do podmiany procedury obsługi wykorzystaj funkcję sigaction().
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include <signal.h>
- #include <unistd.h>
- static void signal_handler(int signum, siginfo_t *info, void *context)
- {
- printf("Sygnal zostal obsluzony przez watek!\n");
- exit(EXIT_SUCCESS);
- }
- void *thread_function(void *p)
- {
- struct sigaction act;
- act.sa_sigaction = &signal_handler;
- if(sigaction(SIGUSR1, &act, NULL) == -1){
- perror("sigaction");
- return (void *)EXIT_FAILURE;
- }
- while(1){}
- return (void *)EXIT_FAILURE;
- }
- int main(void)
- {
- pthread_t thread;
- pthread_create(&thread, NULL, thread_function, (void *)NULL);
- sleep(1);
- printf("Wysylam sygnal do watku...\n");
- pthread_kill(thread, SIGUSR1);
- pthread_join(thread, NULL);
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment