Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include <time.h>
  6. #include <sys/ipc.h>
  7. #include <sys/msg.h>
  8.  
  9. #define NAZWA "/tmp/fifooo"
  10.  
  11. struct msgBuf{
  12.     int mtype;
  13.     time_t czas;
  14. };
  15.  
  16. int main()
  17. {
  18.     if(fork() > 0)
  19.     {
  20.         int fifores = mkfifo(NAZWA,0777);
  21.         int fd;
  22.         if(fork() > 0)
  23.         {
  24.             struct tm czas;
  25.             time_t czassek;
  26.             char tekst[21];
  27.  
  28.             scanf("%s", &tekst);
  29.             strptime(tekst, "%d.%m.%Y/%H:%M:%S", &czas);
  30.             strftime(tekst, 21, "%s", &czas);
  31.             fd = open(NAZWA,O_WRONLY);
  32.             write(fd,tekst, sizeof(tekst));
  33.             close(fd);
  34.         }
  35.         else
  36.         {
  37.             struct tm wczas;
  38.             char buffer[20];
  39.             time_t czas;
  40.             int read_fd = open(NAZWA,O_RDONLY);
  41.             read(read_fd, buffer, 20);
  42.             close(read_fd);
  43.  
  44.             strptime(buffer, "%s", &wczas);
  45.             czas = mktime(&wczas);
  46.  
  47.             key_t klucz;
  48.             int msgID;
  49.  
  50.             if((klucz = ftok(".", 'A')) == -1)
  51.             {
  52.                 printf("Blad ftok (potomny1)\n");
  53.                 exit(1);
  54.             }
  55.  
  56.             msgID = msgget(klucz, IPC_CREAT|0666);
  57.             if (msgID == -1)
  58.             {
  59.                 printf("Blad KK (potomny1)\n");
  60.                 exit(1);
  61.             }
  62.  
  63.             struct msgBuf komunikat;
  64.             komunikat.mtype = 1;
  65.             komunikat.czas = czas;
  66.  
  67.             msgsnd(msgID, &komunikat, sizeof(komunikat.czas), 0);
  68.         }
  69.     }
  70.     else
  71.     {
  72.         execl("pr2", "pr2", NULL);
  73.     }
  74.     wait(NULL);
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement