SIKER_98

121

Dec 8th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <signal.h>
  6.  
  7. pid_t p1;
  8.  
  9. void wypisuj(int sig){
  10. while(1){
  11. printf(".");
  12. fflush(stdout);
  13. sleep(1);
  14. }
  15. }
  16.  
  17. void pauza(int sig){
  18. for(;;) ;
  19. }
  20.  
  21. void przekaz_p(int sig){
  22. kill(p1, sig);
  23. }
  24.  
  25.  
  26. int main(){
  27. int pid0, pid1;
  28. if(fork()==0){
  29. pid0=getpid();
  30. printf("Proces P0 o PID: %d\n", pid0);
  31. signal(SIGINT,przekaz_p);
  32. signal(SIGCONT,przekaz_p);
  33.  
  34. p1=fork();
  35. if(p1==0){
  36. pid1=getpid();
  37. printf("Proces P1 o PID: %d\n\n", pid1);
  38. signal(SIGINT,pauza);
  39. signal(SIGCONT,wypisuj);
  40. wypisuj(1);
  41. }
  42. printf("\n");
  43. return 0;
  44. }
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment