summaryrefslogtreecommitdiff
path: root/userspace/piper.c
blob: f45248e0e29cd7091f758d4da0a9470e249f387f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include "newcalls.h"

int main()
{
    int fds[2];
    _pipe(fds);

    printf("opened pipe / in fd=%d,out fd=%d\n",fds[0],fds[1]);

    int pid=_fork();

    if(pid)
    {
	while(1) // read forever from our pipe and echo to stdout
	{
	    char buf[256];
	    int len=fread(buf,1,255,fds[0]);
	    //int len=_read(fds[0],buf,255);
	    buf[len]=0;
	    printf("-\n");
	    printf("%s\n",buf);
	    printf("-\n");
	}

    }
    else
    {

	// write to our pipe
        _write(fds[1],"Hello\n",fds[1]);
        _write(fds[1],"Bello\n",fds[1]);

	// hang forever
	while(1);
    }

}