Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>FIFO Writer:</p> <pre><code> #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;unistd.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/wait.h&gt; #include &lt;fcntl.h&gt; #define BUFFERSIZE 50 #define CHMOD 0777 int main(int argc, char **argv) { char outbuf[BUFFERSIZE]; // outbuffer int fifo, j, anzahl; // fifo - pipe file deskriptor, j - counter, anzahl - Parameter. if(argc!=2) // Check if parameter is ok { printf("Ungültiger Parameter! Bsp.: ./fifow 10\n"); return 1; } anzahl=atoi(argv[1]); // convert paramter to integer mkfifo("namedpipe4", CHMOD); // make FIFO "namedpipe4" fifo = open("namedpipe4",O_WRONLY); // open FIFO // for(j=0;j&lt;anzahl;j++) { printf("Writer PID: %d writes record nr. %6d\n", getpid(), j+1); sprintf(outbuf, "Writer PID: %d writes record nr. %6d\n", getpid(), j+1); write(fifo, outbuf, BUFFERSIZE); remove("namedpipe4"); // removing the fifo sleep(1); // Wait 1 sec } close(fifo); // exit(0); } </code></pre> <p>FIFO Reader:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;unistd.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/wait.h&gt; #include &lt;fcntl.h&gt; #define BUFFERSIZE 50 int main(void) { char inbuf[BUFFERSIZE]; // inbuffer int fifo, var; printf("\n Waiting for a Pipe....\n"); while((fifo = open("namedpipe4",O_RDONLY)) == -1) // while "there is no such pipe" { remove("namedpipe4"); sleep(1); } while((var = read(fifo, inbuf, BUFFERSIZE)) &gt; 0) // while "i can read" { printf("Reader PID: %d reads record: %s\n", getpid(), inbuf); sleep(1); } close(fifo); // printf("\n EOF..\n"); exit(0); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload