Bash shell to Python shell?

Ned Deily nad at acm.org
Sun Sep 27 23:48:12 EDT 2009


In article <2009092721134550073-edwithad at hotmailcom>,
 edwithad <edwithad at hotmail.com> wrote:
> I am sure you have not read a question this basic in some time, but I 
> am curious. Using Linux I open a terminal window and type: python.
> 
> Does Bash Shell go away and to become a Python Shell, or is it still a 
> Bash Shell with Python running inside? Thanks in advance.

See for youself:

$ ps
  PID TTY          TIME CMD
17478 pts/0    00:00:00 bash
17571 pts/0    00:00:00 ps

$ python
Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('ps')
  PID TTY          TIME CMD
17478 pts/0    00:00:00 bash
17572 pts/0    00:00:00 python
17573 pts/0    00:00:00 sh
17574 pts/0    00:00:00 ps
0
>>>

So you can see that the top-level shell (process id 17478) starts new 
child processes to run other programs (17571 for the ps in the first 
example, 17572 for python in the second), just as the python os.system 
function starts a new shell (17573, a default /bin/sh) to process the 
'ps' argument string passed to it and that shell starts another process 
(17574) to run 'ps'.

For a more detailed explanation of what's going on, see, for example:

http://tldp.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO/running-progra
ms.html

-- 
 Ned Deily,
 nad at acm.org




More information about the Python-list mailing list