Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Napisz program, który stworzy dwa procesy. Proces rodzicielski wy ś le do potomka
- sygnał SIGINT (można go wysłać „ręcznie” naciskając na klawiaturze równocze ś nie
- Ctrl + C). Proces potomny powinien ten sygnał obsłużyć za pomocą napisanej przez
- Ciebie funkcji.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <signal.h>
- void sigint_handler(int signum)
- {
- printf("\nSygnal SIGINT obsluzony przez potomka!\n");
- exit(EXIT_SUCCESS);
- }
- int main(void)
- {
- pid_t pid;
- pid = fork();
- if(pid == 0){
- // Potomek
- if(signal(SIGINT, sigint_handler) == SIG_ERR){
- fprintf(stderr, "Signal error");
- return EXIT_FAILURE;
- }
- while(1){}
- }
- else if(pid > 0){
- // Rodzic
- printf("Wcisnij CTRL + C, aby wyslac sygnal SIGINT\n");
- while(1){}
- }
- else if(pid == -1){
- // Blad
- perror("fork");
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement