Pipe implementation
Posted
by nunos
on Stack Overflow
See other posts from Stack Overflow
or by nunos
Published on 2010-04-17T18:59:29Z
Indexed on
2010/04/17
19:03 UTC
Read the original article
Hit count: 376
I am trying to implement a linux shell that supports piping. I have already done simple commands, commands running in background, redirections, but piping is still missing.
I have already read about it and seen some snippets of code, but still haven't been able to sort out a working solution.
What I have so far:
int fd[2];
pid_t pid = fork();
if (pid == -1)
return -1;
if (pid == 0)
{
dup2(0, fd[0]);
execlp("sort", "sort", NULL);
}
I am a novice programmer, as you can probably tell, and when I am programming something I don't know much about, this being obviously the case, I like to start with something really easy and concrete and then build from there.
So, before being able to implement three and more different commands in pipeline, I would like to be able to compute "ls names.txt | sort" or something similiar, in which names.txt is a file of names alfabetically unordered.
Thanks.
© Stack Overflow or respective owner