--- /dev/null
+#!/usr/bin/env python
+# vim: set et sw=4 sts=4 ts=4
+
+import os, time, sys
+
+if __name__ == '__main__':
+ pid = os.fork()
+ if pid:
+ for i in xrange(100):
+ print "Soy el padre de", pid
+ time.sleep(0.011)
+ (pid, status) = os.waitpid(pid, 0)
+ print "Termino mi hijito", pid, "con estado", status
+ sys.exit(0)
+ else:
+ for i in xrange(100):
+ print "Soy el hijo!"
+ time.sleep(0.01)
+ sys.exit(1)
+
--- /dev/null
+#!/usr/bin/env python
+# vim: set et sw=4 sts=4 ts=4
+
+import os, time, sys, random
+
+def fork_child():
+ pid = os.fork()
+ if not pid:
+ random.seed(time.time())
+ timeout = int(random.random() * 30)
+ # Hijo
+ print "HIJO: Voy a esperar", timeout, "segundos"
+ time.sleep(timeout)
+ sys.exit(timeout)
+
+if __name__ == '__main__':
+ for i in xrange(int(sys.argv[1])):
+ fork_child()
+ for i in xrange(int(sys.argv[1])):
+ (pid, status) = os.wait()
+ timeout = os.WEXITSTATUS(status)
+ print "PADRE: Termino", pid, "despues de esperar", timeout, "segundos"
+
--- /dev/null
+#!/usr/bin/env python
+
+from threading import Thread, Lock
+from sys import argv
+
+minimo = 0
+minimo_lock = Lock()
+
+class Worker(Thread):
+ def __init__(self, lista):
+ Thread.__init__(self)
+ self.lista = lista
+ def run(self):
+ for num in self.lista:
+ minimo_lock.acquire()
+ if num < minimo:
+ minimo = num
+ minimo_lock.release()
+
+cant = int(argv[1])
+lista = argv[2:]
+total = len(lista)
+size = total/cant
+workers = []
+
+print "Lista a ordenar:", lista
+
+for n in xrange(0, total-2):
+ w = Worker(lista[n*size:(n+1)*size])
+ workers.append(w)
+
+for w in workers:
+ w.start()
+
+for w in workers:
+ w.join()
+
--- /dev/null
+
+// Programacion concurrente - Palma Mendez, Garrido Carrera, et al
+
+class ThreadHilo extends Thread
+{
+ String palabra;
+ public ThreadHilo(String frase)
+ {
+ palabra = frase;
+ }
+ public void run()
+ {
+ System.out.println(palabra);
+ }
+ static public void main(String[] args)
+ {
+ Thread a = new ThreadHilo("Pepe");
+ Thread b = new ThreadHilo("Juan");
+ a.start();
+ b.start();
+ System.out.println("Listo");
+ }
+}
+
--- /dev/null
+
+public class ThreadCorrer
+{
+ String palabra;
+ public ThreadCorrer(String frase)
+ {
+ palabra = frase;
+ }
+ public void run()
+ {
+ for (int i = 0; i < 10; i++)
+ System.out.println(palabra);
+ }
+ public static void main(String args[])
+ {
+ ThreadCorrer a = new ThreadCorrer("Pepe");
+ ThreadCorrer b = new ThreadCorrer("Luis");
+ Thread t1 = new Thread(a);
+ Thread t2 = new Thread(b);
+ t1.start();
+ t2.start();
+ System.out.println("Listo!");
+ }
+}
+
+