Search     or:     and:
 LINUX 
 Language 
 Kernel 
 Package 
 Book 
 Test 
 OS 
 Forum 
 iakovlev.org 
      Languages 
      Kernels 
      Packages 
      Books 
      Tests 
      OS 
      Forum 
      Математика 
NEWS
Последние статьи :
  Тренажёр 16.01   
  Эльбрус 05.12   
  Алгоритмы 12.04   
  Rust 07.11   
  Go 25.12   
  EXT4 10.11   
  FS benchmark 15.09   
  Сетунь 23.07   
  Trees 25.06   
  Apache 03.02   
 
TOP 20
 Advanced Bash Scripting G...1859 
 Ethreal 4...1286 
 Secure Programming for Li...1060 
 CPAN-> FAQ...950 
 Intel 386...630 
 Тренажёр...510 
 Go Web ...494 
 Trees...425 
 Ethreal 1...423 
 Максвелл 3...393 
 Alg1...381 
 Rust...369 
 C + UNIX...348 
 Ext4 FS...344 
 Assembler...341 
 William Gropp...337 
 Mod_parrot...329 
 2.0-> Linux IP Networking...326 
 Benchmark...320 
 Rodriguez 6...316 
 
  01.01.2025 : 3803065 посещений 

iakovlev.org
Pipe - механизм взаимодействия между процессами. FIFO повторяет функционал pipe , но применительно через файловую систему . У pipe нет имени , у FIFO имя есть . В следующем примере родительский процесс пишет данные в pipe , которые позже читаются дочерними процессами .
 
 #include < sys/types.h >
 #include < unistd.h >
 #include < stdio.h >
 #include < stdlib.h >
 /* Read characters from the pipe and echo them to stdout. */
 void read_from_pipe (int file)
 {
   FILE *stream;
   int c;
   stream = fdopen (file, "r");
   while ((c = fgetc (stream)) != EOF)
   putchar (c);
   fclose (stream);
 }
 	      
  /* Write some random text to the pipe. */
 void write_to_pipe (int file)
 {
   FILE *stream;
   stream = fdopen (file, "w");
   fprintf (stream, "hello, world!\n");
   fprintf (stream, "goodbye, world!\n");
   fclose (stream);
 }
 intmain (void)
 {
   pid_t pid;
   int mypipe[2];
   /* Create the pipe. */
   if (pipe (mypipe))
   {
     fprintf (stderr, "Pipe failed.\n");
     return EXIT_FAILURE;
   }
   /* Create the child process. */
   pid = fork ();
   if (pid == (pid_t) 0)
   {
     /* This is the child process.    Close other end first. */
    close (mypipe[1]);
    read_from_pipe (mypipe[0]);
    return EXIT_SUCCESS;
   }
   else if (pid < (pid_t) 0)
   {
    /* The fork failed. */
    fprintf (stderr, "Fork failed.\n");
    return EXIT_FAILURE;
   }
   else
   {
    /* This is the parent process.    Close other end first. */
    close (mypipe[0]);
    write_to_pipe (mypipe[1]);
    return EXIT_SUCCESS;
   }
 }
 
В следующем примере показано , как получить данные из другого системного процесса , в данном случае more :
 
 #include < stdio.h >
 #include < stdlib.h >
 
 void
 write_data (FILE * stream)
 {
   int i;
   for (i = 0; i < 100; i++)
     fprintf (stream, "%d\n", i);
   if (ferror (stream))
   {
     fprintf (stderr, "Output to stream failed.\n");
     exit (EXIT_FAILURE);
   }
 }
 int main (void)
 {
   FILE *output;
   output = popen ("more", "w");
   if (!output)
   {
     fprintf (stderr,"incorrect parameters or too many files.\n");
     return EXIT_FAILURE;
   }
   write_data (output);
   if (pclose (output) != 0)
    {
      fprintf (stderr, "Could not run more or other error.\n");
    }
    return EXIT_SUCCESS;
    }
 
При создании FIFO , создается файл , который может быть использован любым процессом.
Оставьте свой комментарий !

Ваше имя:
Комментарий:
Оба поля являются обязательными

 Автор  Комментарий к данной статье