I am working on an assignment to create a simple shell, and I am trying to add a few functions that are not yet needed, but I ran into a problem with channels.
After my team is parsed, I create a process to execute them. This process is a routine that will execute the command if there is only one left, otherwise it will be fork. The parent will execute the first command, the child process will process the rest. The pipes are configured and working correctly.
My main process then calls wait() and then issues a prompt. When I execute a command like ls -la | cat ls -la | cat , the request is displayed before exiting cat.
I tried calling wait() once for every command that needs to be executed, but the first call works, and all subsequent calls return ECHILD .
How to make the main thread wait until all children, including children of children, come out?
source share