Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So when I have 3 tabs open, ps aux | grep bash reports:

$ ps aux | grep bash

root        629   0.0  0.0  2486024   4812 s002  Ss    8:01pm   0:00.02 login -pf moon /bin/bash
moon        513   0.0  0.0  2434460   2508 s001  S+    8:01pm   0:00.07 -bash
root        512   0.0  0.0  2496264   4884 s001  Ss    8:01pm   0:00.02 login -pf moon /bin/bash
moon        381   0.0  0.0  2434460   2500 s000  S+    8:00pm   0:00.09 -bash
root        379   0.0  0.0  2498312   4920 s000  Ss    8:00pm   0:00.03 login -pf moon /bin/bash
moon        740   0.0  0.0  2432768    620 s002  R+    8:01pm   0:00.00 grep bash
moon        630   0.0  0.0  2434460   2500 s002  S     8:01pm   0:00.07 -bash

Why is this happening?

EDIT: Rendering the processes as a tree

 | |-+= 04939 moon /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal -psn_0_2322999
 | | |-+= 04942 root login -pf moon /bin/bash
 | | | \-+= 04943 moon -bash
 | | |   \-+= 05051 moon man login
share|improve this question

1 Answer 1

up vote 3 down vote accepted

Note that it's not two bash processes: It's one bash process, and one login process with options.

This is how Apple implemented the various startup options for new windows and tabs, e.g. whether to use the default or current shell's working directory, or whether to launch the default shell or a specific one.

You'll notice that when you change these options in Terminal's preferences, the login command's arguments change a bit.

If you set every option to default, except the working directory of a new tab, and change the working directory of the current tab, then the new tab's shell will be opened by login -pfl danielbeck /bin/bash -c exec -la bash /bin/bash instead of login -pf danielbeck.

share|improve this answer
    
Thanks for the answer. One question. Is it the login process that is forcing bash to start as a "login shell"? How does it manage to do so? –  0xcafebabe Oct 14 '13 at 1:40
    
@0xcafebabe Either it's login without the -l argument, or it's bash's exec command with the -l argument. See the respective man pages for what these arguments do. –  Daniel Beck Oct 14 '13 at 4:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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