Advertisement
Alx09

Untitled

Jun 1st, 2022
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/socket.h>
  4. #include <arpa/inet.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. #include <signal.h>
  9. #include <sys/stat.h>
  10.  
  11.  
  12. pid_t fiu;
  13. int pipeMesaj[2];
  14. void handlerSIGUSR1(int semnal){
  15.         printf("proces fiu a gasit cuvantul");
  16.     exit(0); // oprim proces parinte   
  17. }
  18. void handlerSIGALRM(){
  19.   printf("proces fiu nu a gasit cuvantul");
  20.   kill(fiu, SIGINT);
  21.   exit(0);// oprim process parinte
  22. }
  23.  
  24. void main(int argc, char * argv[]){
  25. char buffer[500];
  26. int fileIn, bytesRead;
  27. pipe(pipeMesaj);
  28.    if(fiu1 = fork()){ //parinte
  29.    signal(SIGALRM, handlerSIGALRM);
  30.    signal(SIGUSR1, handlerSIGUSR1);
  31.    alarm(5);
  32.    fileIn = open(argv[1], O_RDONLY);   
  33.    close(pipeMesaj[0]);
  34.   while( bytesRead = read(fileIn,  &buffer, sizeof(buffer) != 0)
  35.     write(pipeMesaj[1], &buffer, bytesRead);
  36.  
  37.    
  38.   }
  39.   else{ // fiu
  40.   close(pipeMesaj[1]);
  41.     while(read(pipeMesaj[0], &buffer, sizeof(buffer))){
  42.         if(strstr(buffer, argv[2])!= NULL){
  43.         kill(getppid(), SIGUSR1);
  44.         exit(0);
  45.         }
  46.    
  47.        
  48.   }
  49.  
  50.  
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement