Skip to content

Instantly share code, notes, and snippets.

@theasder
Created December 5, 2013 19:04
Show Gist options
  • Save theasder/7811266 to your computer and use it in GitHub Desktop.
Save theasder/7811266 to your computer and use it in GitHub Desktop.
Shell
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char** argv)
{
int fd[2], status;
int f;
pipe(fd);
if(fork())
{
f = open(argv[4], O_RDONLY);
if(fork()) {
dup2(fd[1], 1);
close(fd[0]);
close(fd[1]);
execlp(argv[1], argv[1], NULL);
return -1;
}
else {
wait(&status);
dup2(fd[1], 1);
dup2(f, 0);
close(fd[0]);
close(fd[1]);
execlp(argv[2], argv[2], NULL);
close(f);
return -1;
}
}
else {
f = open(argv[6], O_WRONLY);
dup2(fd[0], 0);
dup2(f, 1);
close(fd[0]);
close(fd[1]);
execlp(argv[3], argv[3], argv[5], NULL);
close(f);
return -1;
}
while(wait(&status) != -1)
;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment