From 914db3376252f9b86d799afd2a130b8f9892783c Mon Sep 17 00:00:00 2001 From: Juanjo Date: Thu, 3 Oct 2024 12:41:37 +0200 Subject: [PATCH] fork2 --- fork-2.py | 18 ++++++++++++++++++ readme.md | 7 +++---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 fork-2.py diff --git a/fork-2.py b/fork-2.py new file mode 100644 index 0000000..ce9e02b --- /dev/null +++ b/fork-2.py @@ -0,0 +1,18 @@ +from multiprocessing import Process +import os + +def hijo(): + print("Padre: %d, Hijo: %d\n" % ( os.getppid(),os.getpid())) + os._exit(0) + +def padre(): + while True: + p = Process(target=hijo) + p.start() + print ("\nNuevo hijo creado " , p.pid) + p.join() + reply = input("Pulsa 's' si quieres crear un nuevo proceso\n") + if reply != 's': + break +if __name__ == '__main__': + padre() \ No newline at end of file diff --git a/readme.md b/readme.md index 0e22525..0796751 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Ejemplos de fork() con python +# Ejemplos de fork() con python :hourglass: ```python # fork solo funciona en unix/macos @@ -25,8 +25,7 @@ padre() ``` > **fork** solo funciona en unix/macos -:hourglass: - - + +