Advertisement
d1cor

fork_basico.py

Apr 24th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. import os
  2.  
  3. def child():
  4.    print('\nA new child ',  os.getpid())
  5.    os._exit(0)  
  6.  
  7. def parent():
  8.    while True:
  9.       newpid = os.fork()
  10.       if newpid == 0:
  11.          child()
  12.       else:
  13.          pids = (os.getpid(), newpid)
  14.          print("parent: %d, child: %d\n" % pids)
  15.       reply = input("q for quit / c for new fork")
  16.       if reply == 'c':
  17.           continue
  18.       else:
  19.           break
  20.  
  21. parent()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement