Python : fork and exec a process to run on different terminal
I am trying to simulate a a network cons开发者_StackOverflow社区isting of several clients and servers. I have written node.py which contains client-server code. I want to run multiple instances node.py. But I don't want to do it manually so I have written another file spawn.py which spawns multiple instances of node.py using fork and exec. However, I need to run each instance of node.py on different terminal(shell) so that I can easily debug what is happening inside each node. How can we do that? Please help.
EDIT : I am working on linux and using python 2.5 and I want to run all processes on the same box
If you want "real" (pseudo-;-) terminals, and are using X11 (almost every GUI interface on Linux does;-), you could exec xterm -e python node.py
instead of just python node.py
-- substitute for xterm
whatever terminal emulator program you prefer, of course (I'm sure they all have command-line switches equivalent to good old xterm's -e
, to specify what program they should run!-).
shell #1:
for p in 1 2 3 4 5
do
python node.py > $p.log 2>&1
done
shell #2:
tail -F 1.log
shell #3:
tail -F 2.log
etc...
精彩评论