Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<signal.h>
- #include <unistd.h>
- int main()
- {
- if (fork()==0)
- {
- execl("./p1","p1",NULL);
- }
- if (fork()==0)
- execlp("./p2","p2",NULL);
- for(;;) pause();
- return 0;
- }
- //////////////////////////
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include<unistd.h>
- #include<signal.h>
- #include<sys/types.h>
- void wyp(int sig)
- {
- FILE *f;
- int i;
- char tekst [15];
- if ((f=fopen("zaszyf.txt", "r")) == NULL)
- {
- printf("Nie moge otworzyc pliku do odczytu.\n");
- exit(1);
- }
- fscanf(f,"%s", tekst);
- printf("Zaszyfrowany tekst: %s\n",tekst);
- fclose(f);
- system("pkill -SIGKILL p1");
- }
- int main()
- {
- FILE *f;
- char tekst[15];
- printf("Podaj tekst jawny: ");
- scanf("%s", tekst);
- if ((f=fopen("jawny.txt", "w")) == NULL)
- {
- printf("Nie moge otworzyc pliku do zapisu.\n");
- exit(1);
- }
- fprintf(f, "%s", tekst);
- fclose (f);
- system("killall -SIGUSR1 p2");
- while(1)
- {
- signal(SIGUSR2,wyp);
- }
- return 0;
- }
- /////////////////////
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include<unistd.h>
- #include<signal.h>
- #include<sys/types.h>
- void szyfr(int sig)
- {
- FILE *f;
- int i;
- char tekst [15];
- if ((f=fopen("jawny.txt", "r")) == NULL)
- {
- printf("Nie moge otworzyc pliku do odczytu.\n");
- exit(1);
- }
- fscanf(f,"%s", tekst);
- for (i=0; i<strlen(tekst); i++)
- {
- tekst[i]=tekst[i]+2;
- }
- fclose(f);
- if ((f=fopen("zaszyf.txt", "w"))==NULL)
- {
- printf("Nie moge otworzyc pliku do zapisu.\n");
- exit(1);
- }
- fprintf (f, "%s", tekst);
- fclose (f);
- system("killall -SIGUSR2 p1");
- pause();
- }
- int main()
- {
- while(1)
- {
- signal(SIGUSR1,szyfr);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement