Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<signal.h>
  3. #include <unistd.h>
  4.  
  5. int main()
  6.  
  7. {
  8. if (fork()==0)
  9. {
  10. execl("./p1","p1",NULL);
  11.  
  12.  
  13. }
  14.  
  15. if (fork()==0)
  16. execlp("./p2","p2",NULL);
  17. for(;;) pause();
  18. return 0;
  19. }
  20. //////////////////////////
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include<unistd.h>
  25. #include<signal.h>
  26. #include<sys/types.h>
  27.  
  28. void wyp(int sig)
  29. {
  30. FILE *f;
  31. int i;
  32. char tekst [15];
  33.  
  34. if ((f=fopen("zaszyf.txt", "r")) == NULL)
  35. {
  36. printf("Nie moge otworzyc pliku do odczytu.\n");
  37. exit(1);
  38. }
  39.  
  40. fscanf(f,"%s", tekst);
  41. printf("Zaszyfrowany tekst: %s\n",tekst);
  42.  
  43. fclose(f);
  44.  
  45. system("pkill -SIGKILL p1");
  46. }
  47.  
  48.  
  49. int main()
  50. {
  51. FILE *f;
  52. char tekst[15];
  53. printf("Podaj tekst jawny: ");
  54. scanf("%s", tekst);
  55. if ((f=fopen("jawny.txt", "w")) == NULL)
  56. {
  57. printf("Nie moge otworzyc pliku do zapisu.\n");
  58. exit(1);
  59. }
  60.  
  61. fprintf(f, "%s", tekst);
  62. fclose (f);
  63.  
  64. system("killall -SIGUSR1 p2");
  65.  
  66. while(1)
  67. {
  68. signal(SIGUSR2,wyp);
  69. }
  70.  
  71. return 0;
  72. }
  73. /////////////////////
  74. #include <stdio.h>
  75. #include <stdlib.h>
  76. #include <string.h>
  77. #include<unistd.h>
  78. #include<signal.h>
  79. #include<sys/types.h>
  80.  
  81. void szyfr(int sig)
  82. {
  83. FILE *f;
  84. int i;
  85. char tekst [15];
  86.  
  87. if ((f=fopen("jawny.txt", "r")) == NULL)
  88. {
  89. printf("Nie moge otworzyc pliku do odczytu.\n");
  90. exit(1);
  91. }
  92.  
  93. fscanf(f,"%s", tekst);
  94. for (i=0; i<strlen(tekst); i++)
  95. {
  96. tekst[i]=tekst[i]+2;
  97. }
  98.  
  99. fclose(f);
  100.  
  101. if ((f=fopen("zaszyf.txt", "w"))==NULL)
  102. {
  103. printf("Nie moge otworzyc pliku do zapisu.\n");
  104. exit(1);
  105. }
  106.  
  107. fprintf (f, "%s", tekst);
  108. fclose (f);
  109.  
  110. system("killall -SIGUSR2 p1");
  111. pause();
  112. }
  113.  
  114.  
  115. int main()
  116. {
  117. while(1)
  118. {
  119. signal(SIGUSR1,szyfr);
  120. }
  121.  
  122. return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement