#! /usr/bin/env python import sys,os,errno N_wait = 2 for i in range(N_wait): pid = os.fork() if pid == 0: # child sys.exit(100+i) try: # parent waits for all of its children to terminate (pid,statut) = os.waitpid(-1,0) while True: if os.WIFEXITED(statut): print("child %d terminated normally with exit status=%d" %\ (pid, os.WEXITSTATUS(statut))) else: print("child %d terminated abnormally" % (pid)) (pid,statut) = os.waitpid(-1,0) except OSError as err: #print ("{}".format(err)) if err.errno != errno.ECHILD: print("waitpid error(%d): %s" % (err,strerror(err.errno))) sys.exit(0)