Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <arpa/inet.h>
- #include <string.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <sys/wait.h>
- pid_t fiu;
- int pipeMesaj[2];
- void handlerSIGUSR1(int semnal){
- printf("proces fiu a gasit cuvantul\n");
- exit(0); // oprim proces parinte
- }
- void handlerSIGALRM(){
- printf("proces fiu nu a gasit cuvantul\n");
- kill(fiu, SIGINT);
- exit(0);// oprim process parinte
- }
- void main(int argc, char * argv[]){
- char buffer[500];
- int fileIn, bytesRead;
- pipe(pipeMesaj);
- if(fiu = fork()){ //parinte
- signal(SIGALRM, handlerSIGALRM);
- signal(SIGUSR1, handlerSIGUSR1);
- alarm(5);
- fileIn = open(argv[1], O_RDONLY);
- close(pipeMesaj[0]);
- while( bytesRead = read(fileIn, &buffer, sizeof(buffer)) != 0)
- write(pipeMesaj[1], &buffer, sizeof(buffer));
- wait(0);
- }
- else{ // fiu
- close(pipeMesaj[1]);
- while(read(pipeMesaj[0], &buffer, sizeof(buffer)) != 0){
- if(strstr(buffer, argv[2]) != NULL){
- kill((int)getppid(), SIGUSR1);
- exit(0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement