shell - Multi Piping bash-style in C -
i know there many threads talk problem don't understand way can done.
i'm trying make shell can execute linux command sucha ps | grep | less
i've donne parsing puting every command , args in linked list.
here's implementation doesn't work. hope that's clear enough.
if ((son = fork()) < 0) return printerr_sys("unable fork", 0); if (son == 0) { if (first > 1 && data->format[first - 1] && is_directing_elt(data->format[first - 1]) == direct_tpipe) dup2(tube_p[0], stdin_fileno); first = make_argv(data, first, &argv); if (next) { dup2(tube_v[1], stdout_fileno); close(tube_v[0]); } if (execvp(argv[0], argv) < 0) return printerr_cmd(argv[0], 1); } else { if (next) { close(tube_v[1]); cmdline_executer(data, next, tube_v); } waitpid(son, &(data->lastcmd), wuntraced); data->lastcmd = wexitstatus(data->lastcmd); } return true;
my questions are:
- what correct implementation?
- is possible recursion?
- do need fork right left or left right (logically give same result)?
processes run independently, need set pipe @ least first pair of commands before fork, you're doing in child (son == 0). code recursive solution that, long there @ least 2 commands left, creates pipe, forks, runs first command.
Comments
Post a Comment