#include #include int main(){ // make a pipe int pipe_fds[2]; // read end is pipe_fds[0], write end is pipe_fds[1] pipe(pipe_fds); char *cmd1 = "who"; char *cmd2 = "sed"; char *cmd2_argument = "s/i/A/g"; // Run cmd1 | cmd2, in this case: who | sed s/i/A/g pid_t pid = fork(); if(pid){ // We're the parent dup2(pipe_fds[1], 1); execlp(cmd1, cmd1, 0); perror("running who"); } else { // We're the child dup2(pipe_fds[0], 0); execlp(cmd2, cmd2, cmd2_argument, 0); } // This won't print puts("Reached the end of the program\n"); return 0; }