diff options
author | Peter Wu <lekensteyn@gmail.com> | 2012-09-26 15:04:18 +0200 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2012-09-26 15:04:18 +0200 |
commit | 2497c1392b81e093f4de2541a98746aebd449a7f (patch) | |
tree | db87e59d4c70c677ddb1899d9161b004f6e454ac /pipe.c | |
download | c-files-2497c1392b81e093f4de2541a98746aebd449a7f.tar.gz |
Initial commit
Diffstat (limited to 'pipe.c')
-rw-r--r-- | pipe.c | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -0,0 +1,35 @@ +#include <unistd.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <stdlib.h> +#include <fcntl.h> + +#define F(cmd) ( (r=cmd),r<0?(perror(#cmd),exit(1),r):r ) + +int main() { + int r; + int pA[2]; + int f = F(open("mehlog", O_CREAT | O_APPEND | O_WRONLY, 0644)); + pipe(pA); + //pipe(pB); + if (!F(fork())) { + close(f); + dup2(pA[1], STDOUT_FILENO); + close(pA[0]); + close(pA[1]); + F(execlp("cat", "cat", NULL)); + } + close(pA[1]); + if (!F(fork())) { + dup2(f, STDOUT_FILENO); + dup2(pA[0], STDIN_FILENO); + close(pA[0]); + close(f); + F(execlp("rev", "rev", NULL)); + } + close(pA[0]); + close(f); + wait(NULL); + return 0; +} |