Hi, I will try to keep my post as compressed as my title was.
I am writing on pseudo code on a recursive function that I want to read from the one-above function-run and then give the result to the function-run down below until a stop is triggered. Example:
$ ls -la | grep x | sort
In my function what I want ls to run and send the result to the next function call.
What I've got so far:
main:
create a char **program_names and set int times_to_run to amount of names.
call rec(program_names, times_to_run)
rec(char** program_names, int times_to_run):
if times_to_run is 0 return, else do
int fd[2]
pipe(fd)
replace stdout with fd[1]
fork
parent:
execl(*(program_names+times_to_run))
child:
replace stdin with fd[0]
//waitpid(getppid()) ?
call rec(program_names, times_to_run-1)
Does this seem right? I'm having a hard time with recursion. :wall:
Cheers.