I have a simple doubt on execution of the command ls. As per my understanding from the research I have done on the internet, I understood the below points.
When we type
lscommand shell interprets that command.Then the shell process forks and creates the child process and the parent (shell) executes the
wait()system call, effectively putting itself to sleep until the child exits.Child process inherits all the open file descriptors and the environment.
The child process (shell) executes an
exec()of thelsprogram, causing thelsbinary being loaded from the disk (filesystem) and being executed in the same process.When the
lsprogram runs to completion, it callsexit(), and the kernel sends a signal to its parent indicating the child has terminated.
My doubt starts from here onwards, as soon as ls finishes its tasks; does it send the result back to the parent process, or does it display the output to the screen?
If it sends the output back to parent, then is it using pipe() implicitly?
exec(), though, but that happens within the same child process