From f3d7abf757e935d6a380f30326537c7f2c00441d Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 20 Oct 2023 18:43:57 +0200 Subject: [PATCH] Upload EjercicioPs2Python --- README.md | 8 ++++++++ ps2.py | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 README.md create mode 100644 ps2.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c32644 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Ejercicio PS2 Python + +~~~ text +Nuevo hijo creado 24353 +Padre: 24352, Hijo: 24353 + +Pulsa 's' si quieres crear un nuevo proceso +~~~ diff --git a/ps2.py b/ps2.py new file mode 100644 index 0000000..72cab95 --- /dev/null +++ b/ps2.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