Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Zademonstruj dziaΕanie funkcji sigwait()
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include <signal.h>
- #include <unistd.h>
- void *thread_function(void *p)
- {
- static sigset_t set;
- int sig;
- printf("Oczekiwanie na sygnal: \n");
- sigemptyset(&set);
- if(sigaddset(&set, SIGUSR1) == -1){
- perror("sigaddset");
- return (void *)EXIT_FAILURE;
- }
- if(sigwait(&set, &sig) != SIGUSR1){
- perror("sigwait");
- return (void *)EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- int main(void)
- {
- pthread_t thread;
- pthread_create(&thread, NULL, thread_function, (void *)NULL);
- sleep(2);
- pthread_kill(thread, SIGUSR1);
- pthread_join(thread, NULL);
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment