Advertisement
vakho

Sistemebi - Kodi

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