Advertisement
vakho

Sistemebi - Kodi [FIFO]

Jan 11th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. /* IGIVE OGOND FIFO-TI!!!!! */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6.  
  7. /*
  8.  * amocana:
  9.  *  # mshobelma FIFO-shi chaweros monacemebi
  10.  *  # shvilma es 'str' FIFO-dan waikitxos;
  11.  *  # shvilma chaweros es 'str' failshi;
  12.  *  # amis shemdeg mshobelma daakompiliros da gaushvas!
  13.  */
  14. int main()
  15. {
  16.   char str[] = "ragaca kodi!...";
  17.   char str2[N]; // N vigulisxmot rom vicit da aris str-shi simboloebis raodenoba!
  18.  
  19.   int pr, FIFO, status, fd;
  20.  
  21.   (void)umask(0);
  22.   FIFO = mknod("asdf.fifo", S_IFIFO | 0754, 0)
  23.   if (FIFO == -1) exit(-1);
  24.  
  25.   pr = fork();
  26.   if (pr == -1) exit(-1);
  27.  
  28.   if (pr != 0) // mshobeli:
  29.   {
  30.     // # mshibelma chaweros str kodi FIFO-shi!
  31.     fd = open("asdf.fifo", O_WRONLY);
  32.     if (fd == -1) exit(-1);
  33.     if (write(fd, str, sizeof(str)) != sizeof(str)) exit(-1);
  34.     close(fd);
  35.     wait(&status);
  36.     // chaweris shemdeg unda davacompilirot da mere gavushvat!
  37.     execl("usr/bin/gcc", "gcc", "test.c", "-o", "test.out");
  38.     execl("test.out","./test.out", NULL);
  39.   }
  40.   else // shvili:
  41.   {
  42.     // # shvilma FIFO-dan waikitxos da chaweros failshi
  43.     fd = open("asdf.fifo", O_RDONLY);
  44.     if (fd == -1) exit(-1);
  45.     if (read(fd, str2, sizeof(str2)) != sizeof(str2)) exit(-1);
  46.     close(fd);
  47.     (void) umask(0);
  48.     fd = open("test.c", O_WRONLY | O_CREAT, 0756);
  49.     if (fd == -1) exit(-1);
  50.     if (write(fd, str2, sizeof(str2)) != sizeof(str2)) exit(-1);
  51.     // vsio sheiqmna faili da chaiwera!
  52.   }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement