Skip to content

Instantly share code, notes, and snippets.

@Silva97
Created June 17, 2020 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Silva97/0691f9b6a48f5b9804385002f0805ce6 to your computer and use it in GitHub Desktop.
Save Silva97/0691f9b6a48f5b9804385002f0805ce6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
enum {
READ = 0,
WRITE,
};
int main(void)
{
int fd[2];
pipe(fd);
if ( fork() > 0 ) {
dup2(fd[WRITE], STDOUT_FILENO);
execv("/bin/cat", (char *[]){"cat", "tst.c", NULL});
}
dup2(fd[READ], STDIN_FILENO);
execv("/bin/grep", (char *[]){"grep", "exec", NULL});
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment