Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////PISARZ///////////////////////////
- #include <stdio.h>
- #include <signal.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <string.h>
- void signalHandler(int signalNumber, siginfo_t* senderInfo, void* dummy)
- {
- sleep(2);
- FILE* input = fopen("/etc/passwd", "r");
- char tmp[200];
- int output = open("bufor", O_WRONLY | O_CREAT, 777);
- while(fgets(tmp, 200, input))
- {
- write(output, tmp, strlen(tmp)+1);
- memset(tmp, 0, 200);
- kill(senderInfo->si_pid, SIGUSR2);
- sleep(1);
- lseek(output, 0L, 0);//ustawia kursor pliku wyjsciowego na poczatek
- //write(output, tmp, 200); // zapisuje tmp do pliku wyjsciowego
- //lseek(output, 0L, 0); //ustawia kuror pliku wyjsciowego na poczatek
- }
- fclose(input);
- close(output);
- remove("bufor");
- }
- int main()
- {
- struct sigaction signalInterface;
- signalInterface.sa_sigaction = &signalHandler;
- signalInterface.sa_flags = SA_SIGINFO;
- if(sigaction(SIGUSR1, &signalInterface, NULL) < 0)
- {
- perror("sigaction");
- return 1;
- }
- printf("Moj ID: %d\n", getpid());
- while(1);
- return 0;
- }
- ///////////////////CZYTELNIK///////////////////////
- #include <stdio.h>
- #include <signal.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <string.h>
- int pisarzID;
- void signalHandler(int syg)
- {
- int input = open("bufor", O_RDONLY);
- char tmp[200];
- read(input, tmp, 200);
- printf("%s", tmp);
- //kill(pisarzID, SIGUSR1);
- fflush(stdout);
- close(input);
- }
- int main()
- {
- signal(SIGUSR2, signalHandler);
- printf("Wprowadz numer ID pisarza: ");
- scanf("%d", &pisarzID);
- printf("\n");
- kill(pisarzID, SIGUSR1);
- while(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement