From e3b9139653629210c6e9aa28ee8c363b519419c5 Mon Sep 17 00:00:00 2001 From: Juanjo Date: Thu, 3 Oct 2024 12:03:19 +0200 Subject: [PATCH] fork-1 --- fork1.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 fork1.py diff --git a/fork1.py b/fork1.py new file mode 100644 index 0000000..353afb8 --- /dev/null +++ b/fork1.py @@ -0,0 +1,20 @@ +# fork solo funciona en unix/macos +import os + +def padre(): + while True: + newpid = os.fork() + if newpid == 0: + hijo() + else: + pids = (os.getpid(), newpid) + print("Padre: %d, Hijo: %d\n" % pids) + reply = input("Pulsa 's' si quieres crear un nuevo proceso") + if reply != 's': + break + +def hijo(): + print('\n>>>>>>>>>> Nuevo hijo creado con el pid %d a punto de finalizar<<<<<' % os.getpid()) + os._exit(0) + +padre() \ No newline at end of file