-5

This is a Diagram for what happens after one has entered ls in the bash and executed it: enter image description here

the first part shows the situation before ls is executed. Bash is a childprocess of the terminal emulator xterm and they have the same aura, the environment, around them. The xx marks indicate, that both Xterm and Bash, as Father-and Sonprocesses posess the identical set of environment variables.

the second part shows what happens after one has started a new process, namely ls.

  1. Bash fathers a childprocess,which is an exact copy of itself, therefore I named it Bash_c (short for Bash_copy).
  2. Then, Bash_c is being replaced by the ls process.

I think this diagram is straightforwarded, selfexplanatory, intuitive and non-ambiguous.

However, I have not drawn a diagram for (ls), because I do not know how it looks like, I have a few different scenarios for how it could look like, but here starts the question part: How would a diagram for (ls) look like? please draw and comment.

  • 1
    The details are a lot more involved than that, but yes, running a program is essentially a fork() followed by an exec(). – Satō Katsura May 30 '17 at 5:43
  • thanks for mentioning the two : fork(), exec(), did not know about "system signals" before, I made the diagram based on a wiki about bash, but they did not mention them – sharkant May 30 '17 at 8:13
0

The process hierachy for (ls) is the same as for ls, i.e. → bash → ls, but if you put a list of commands the the parentheses: (ls; ls), then bash starts a subshell and runs the commands in that subshell. The resulting process hierachy looks like this: → bash → bash → ls (the two ls processes are run in sequence).

You can visualise this by using cat without arguments instead of ls: (cat; cat). The first cat process waits for input giving you a chance to see what's going on using pstree or top in another terminal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.