Created
July 19, 2018 20:45
-
-
Save offlinemark/287eb1e3d3094df138d0541e658e6e18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import os | |
def child(sock): | |
print 'child running! echo server starting' | |
while True: | |
ret = sock.recv(64) | |
if ret == '': | |
print 'child server exiting!' | |
break | |
sock.sendall('hi ' + ret ) | |
def parent(sock): | |
print 'parent running!' | |
print 'heres your control shell' | |
while True: | |
inp = raw_input('>') | |
sock.sendall(inp) | |
ret = sock.recv(128) | |
if ret == '': | |
print 'parent exiting' | |
break | |
print 'got back from child:', ret | |
a, b = socket.socketpair(socket.AF_UNIX, socket.SOCK_DGRAM) | |
import IPython; IPython.embed() | |
print 'init running, make the sockets' | |
print 'forking' | |
ret = os.fork() | |
if ret == 0: | |
# child | |
child(b) | |
else: | |
# parent | |
parent(a) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment