Reputation: 51
I need to implement ps -auxj, grep "user id", and wc. I already have word count, but I'm not sure how to do the others while they have parameters. This is what I have so far.
int main() {
int pfd[2];
int pid;
if (pipe(pfd) == -1) {
perror("pipe failed");
exit(-1);
}
if ((pid = fork()) < 0) {
perror("fork failed");
exit(-2);
}
if (pid == 0) {
close(pfd[1]);
dup2(pfd[0], 0);
close(pfd[0]);
execlp("wc", "wc", (char *) 0);
perror("wc failed");
exit(-3);
}
else {
close(pfd[0]);
dup2(pfd[1], 1);
close(pfd[1]);
execlp("ls", "ls", (char *) 0);
perror("ls failed");
exit(-4);
}
exit(0);
}
Any help in the right direction would be great.
Upvotes: 0
Views: 110