1 # Copyright (c) 2017-2019. The SimGrid Team. All rights reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the license (GNU LGPL) which comes with this package.
11 this_actor.on_exit(lambda: this_actor.info("I have been killed!"))
12 this_actor.info("Hello!")
13 this_actor.info("Suspending myself")
14 this_actor.suspend() # - Start by suspending itself
15 # - Then is resumed and start to execute a task
16 this_actor.info("OK, OK. Let's work")
17 this_actor.execute(1e9)
18 # - But will never reach the end of it
19 this_actor.info("Bye!")
23 this_actor.info("Terminate before being killed")
27 this_actor.info("Hello!") # - First start a victim process
28 victim_a = Actor.create("victim A", Host.by_name("Fafard"), victim_a_fun)
29 victim_b = Actor.create("victim B", Host.by_name("Jupiter"), victim_b_fun)
30 this_actor.sleep_for(10) # - Wait for 10 seconds
32 # - Resume it from its suspended state
33 this_actor.info("Resume the victim A")
35 this_actor.sleep_for(2)
37 this_actor.info("Kill the victim A") # - and then kill it
38 Actor.by_pid(victim_a.pid).kill() # You can retrieve an actor from its PID (and then kill it)
40 this_actor.sleep_for(1)
42 # that's a no-op, there is no zombies in SimGrid
43 this_actor.info("Kill victim B, even if it's already dead")
46 this_actor.sleep_for(1)
48 this_actor.info("Start a new actor, and kill it right away")
49 victim_c = Actor.create("victim C", Host.by_name("Jupiter"), victim_a_fun)
52 this_actor.sleep_for(1)
54 this_actor.info("Killing everybody but myself")
57 this_actor.info("OK, goodbye now. I commit a suicide.")
61 "This line never gets displayed: I'm already dead since the previous line.")
64 if __name__ == '__main__':
68 "Usage: actor-kill.py platform_file [other parameters]")
70 e.load_platform(sys.argv[1]) # Load the platform description
71 # Create and deploy killer process, that will create the victim actors
72 Actor.create("killer", Host.by_name("Tremblay"), killer)