include examples/c/actor-daemon/actor-daemon.tesh
include examples/c/actor-join/actor-join.c
include examples/c/actor-join/actor-join.tesh
+include examples/c/actor-kill/actor-kill.c
+include examples/c/actor-kill/actor-kill.tesh
include examples/c/app-pingpong/app-pingpong.c
include examples/c/app-pingpong/app-pingpong.tesh
include examples/c/app-pingpong/app-pingpong_d.xml
include teshsuite/msg/platform-properties/platform-properties_d.xml
include teshsuite/msg/plugin-hostload/plugin-hostload.c
include teshsuite/msg/plugin-hostload/plugin-hostload.tesh
-include teshsuite/msg/process-kill/process-kill.c
-include teshsuite/msg/process-kill/process-kill.tesh
include teshsuite/msg/process-lifetime/baseline_d.xml
include teshsuite/msg/process-lifetime/kill_d.xml
include teshsuite/msg/process-lifetime/process-lifetime.c
-foreach(x actor-create actor-daemon actor-join app-pingpong app-token-ring async-waitany io-disk-raw)
+foreach(x
+ actor-create actor-daemon actor-join actor-kill
+ app-pingpong app-token-ring async-waitany io-disk-raw)
add_executable (${x}-c EXCLUDE_FROM_ALL ${x}/${x}.c)
target_link_libraries(${x}-c simgrid)
set_target_properties(${x}-c PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x})
${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/async-waitany_d.xml
PARENT_SCOPE)
-foreach(x actor-create actor-daemon actor-join app-pingpong app-token-ring async-waitany io-disk-raw)
+foreach(x
+ actor-create actor-daemon actor-join actor-kill
+ app-pingpong app-token-ring async-waitany io-disk-raw)
ADD_TESH(c-${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
--setenv bindir=${CMAKE_BINARY_DIR}/examples/c/${x}
--cd ${CMAKE_HOME_DIRECTORY}/examples/c/${x}
--- /dev/null
+/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "simgrid/actor.h"
+#include "simgrid/engine.h"
+#include "simgrid/host.h"
+
+#include "xbt/log.h"
+#include "xbt/sysdep.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(actor_kill, "Messages specific for this example");
+
+static int victim_on_exit(XBT_ATTRIB_UNUSED int ignored1, XBT_ATTRIB_UNUSED void* ignored2)
+{
+ XBT_INFO("I have been killed!");
+ return 0;
+}
+
+static void victimA_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+{
+ sg_actor_on_exit(&victim_on_exit, NULL);
+ XBT_INFO("Hello!");
+ XBT_INFO("Suspending myself");
+ sg_actor_suspend(sg_actor_self()); /* - First suspend itself */
+ XBT_INFO("OK, OK. Let's work"); /* - Then is resumed and start to execute a task */
+ sg_actor_self_execute(1e9);
+ XBT_INFO("Bye!"); /* - But will never reach the end of it */
+}
+
+static void victimB_fun()
+{
+ XBT_INFO("Terminate before being killed");
+}
+
+static void killer_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+{
+ XBT_INFO("Hello!"); /* - First start a victim process */
+ sg_actor_t victimA = sg_actor_init("victim A", sg_host_by_name("Fafard"));
+ sg_actor_start(victimA, victimA_fun, 0, NULL);
+ sg_actor_t victimB = sg_actor_init("victim B", sg_host_by_name("Jupiter"));
+ sg_actor_start(victimB, victimB_fun, 0, NULL);
+ sg_actor_sleep_for(10.0);
+
+ XBT_INFO("Resume the victim A"); /* - Resume it from its suspended state */
+ sg_actor_resume(victimA);
+ sg_actor_sleep_for(2.0);
+
+ XBT_INFO("Kill the victim A"); /* - and then kill it */
+ sg_actor_kill(victimA);
+ sg_actor_sleep_for(1.0);
+
+ XBT_INFO("Kill victimB, even if it's already dead"); /* that's a no-op, there is no zombies in SimGrid */
+ sg_actor_kill(victimB); // the actor is automatically garbage-collected after this last reference
+ sg_actor_sleep_for(1.0);
+
+ XBT_INFO("Start a new actor, and kill it right away");
+ sg_actor_t victimC = sg_actor_init("victim C", sg_host_by_name("Jupiter"));
+ sg_actor_start(victimC, victimA_fun, 0, NULL);
+ sg_actor_kill(victimC);
+ sg_actor_sleep_for(1.0);
+
+ XBT_INFO("Killing everybody but myself");
+ sg_actor_kill_all();
+
+ XBT_INFO("OK, goodbye now. I commit a suicide.");
+ sg_actor_exit();
+
+ XBT_INFO("This line will never get displayed: I'm already dead since the previous line.");
+}
+
+int main(int argc, char* argv[])
+{
+ simgrid_init(&argc, argv);
+ xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
+
+ simgrid_load_platform(argv[1]);
+
+ /* - Create and deploy killer process, that will create the victim process */
+ sg_actor_t killer = sg_actor_init("killer", sg_host_by_name("Tremblay"));
+ sg_actor_start(killer, killer_fun, 0, NULL);
+
+ simgrid_run();
+
+ return 0;
+}
--- /dev/null
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/actor-kill-c ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [ 0.000000] (killer@Tremblay) Hello!
+> [ 0.000000] (victim A@Fafard) Hello!
+> [ 0.000000] (victim A@Fafard) Suspending myself
+> [ 0.000000] (victim B@Jupiter) Terminate before being killed
+> [ 10.000000] (killer@Tremblay) Resume the victim A
+> [ 10.000000] (victim A@Fafard) OK, OK. Let's work
+> [ 12.000000] (killer@Tremblay) Kill the victim A
+> [ 12.000000] (victim A@Fafard) I have been killed!
+> [ 13.000000] (killer@Tremblay) Kill victimB, even if it's already dead
+> [ 14.000000] (killer@Tremblay) Start a new actor, and kill it right away
+> [ 14.000000] (victim C@Jupiter) I have been killed!
+> [ 15.000000] (killer@Tremblay) Killing everybody but myself
+> [ 15.000000] (killer@Tremblay) OK, goodbye now. I commit a suicide.
*
* Note that argv is copied over, so you should free your own copy once the actor is started. */
XBT_PUBLIC void sg_actor_start(sg_actor_t actor, xbt_main_func_t code, int argc, const char* const* argv);
+XBT_PUBLIC void sg_actor_exit();
+XBT_PUBLIC void sg_actor_on_exit(int_f_int_pvoid_t fun, void* data);
+
XBT_PUBLIC aid_t sg_actor_get_PID(const_sg_actor_t actor);
XBT_PUBLIC aid_t sg_actor_get_PPID(const_sg_actor_t actor);
XBT_PUBLIC sg_actor_t sg_actor_by_PID(aid_t pid);
}
/* ************************** Actors *************************** */
+void MSG_process_on_exit(int_f_int_pvoid_t fun, void* data)
+{
+ sg_actor_on_exit(fun, data);
+}
+
int MSG_process_get_PID(const_sg_actor_t actor)
{
return sg_actor_get_PID(actor);
}
return res;
}
-
-/** @brief Add a function to the list of "on_exit" functions for the current process.
- * The on_exit functions are the functions executed when your process is killed.
- * You should use them to free the data used by your process.
- */
-void MSG_process_on_exit(int_f_int_pvoid_t fun, void* data)
-{
- simgrid::s4u::this_actor::on_exit([fun, data](bool failed) { fun(failed ? 1 /*FAILURE*/ : 0 /*SUCCESS*/, data); });
-}
actor->start(std::move(function));
}
+void sg_actor_exit()
+{
+ simgrid::s4u::this_actor::exit();
+}
+
/** @ingroup m_actor_management
* @brief Returns the process ID of @a actor.
*
* This function checks whether @a actor is a valid pointer and return its PID (or 0 in case of problem).
*/
+
aid_t sg_actor_get_PID(const_sg_actor_t actor)
{
/* Do not raise an exception here: this function is called by the logs
{
actor->set_data(userdata);
}
+/** @brief Add a function to the list of "on_exit" functions for the current process.
+ * The on_exit functions are the functions executed when your process is killed.
+ * You should use them to free the data used by your process.
+ */
+void sg_actor_on_exit(int_f_int_pvoid_t fun, void* data)
+{
+ simgrid::s4u::this_actor::on_exit([fun, data](bool failed) { fun(failed ? 1 /*FAILURE*/ : 0 /*SUCCESS*/, data); });
+}
foreach(x async-wait async-waitall async-waitany
cloud-capping cloud-migration cloud-two-tasks cloud-simple
get_sender host_on_off host_on_off_recv
- process-kill process-lifetime process-migration process-suspend process-yield
+ process-lifetime process-migration process-suspend process-yield
energy-consumption energy-ptask energy-pstate platform-properties
io-file io-file-remote
task-priority
host_on_off host_on_off_processes host_on_off_recv
get_sender
task_destroy_cancel task_listen_from task_progress
- process-kill process-lifetime process-migration process-suspend process-yield
+ process-lifetime process-migration process-suspend process-yield
energy-consumption energy-ptask
io-file io-file-remote
platform-properties
+++ /dev/null
-/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "simgrid/msg.h"
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_process_kill, "Messages specific for this msg example");
-
-static int victim_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
-{
- XBT_INFO("Hello!");
- XBT_INFO("Suspending myself");
- MSG_process_suspend(MSG_process_self()); /* - First suspend itself */
- XBT_INFO("OK, OK. Let's work"); /* - Then is resumed and start to execute a task */
- MSG_task_execute(MSG_task_create("work", 1e9, 0, NULL));
- XBT_INFO("Bye!"); /* - But will never reach the end of it */
- return 0;
-}
-
-static int killer(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
-{
- XBT_INFO("Hello!"); /* - First start a victim process */
- msg_process_t victim = MSG_process_create("victim", victim_fun, NULL, MSG_host_by_name("Fafard"));
- MSG_process_sleep(10.0);
-
- XBT_INFO("Resume victim"); /* - Resume it from its suspended state */
- MSG_process_resume(victim);
-
- XBT_INFO("Kill victim"); /* - and then kill it */
- MSG_process_kill(victim);
-
- XBT_INFO("OK, goodbye now. I commit a suicide.");
- MSG_process_kill(MSG_process_self());
-
- XBT_INFO("This line will never get displayed: I'm already dead since the previous line.");
- return 0;
-}
-
-int main(int argc, char* argv[])
-{
- MSG_init(&argc, argv);
- xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
-
- MSG_create_environment(argv[1]); /* - Load the platform description */
- /* - Create and deploy killer process, that will create the victim process */
- MSG_process_create("killer", killer, NULL, MSG_host_by_name("Tremblay"));
-
- msg_error_t res = MSG_main(); /* - Run the simulation */
-
- XBT_INFO("Simulation time %g", MSG_get_clock());
- return res != MSG_OK;
-}
+++ /dev/null
-#!/usr/bin/env tesh
-
-p Testing a MSG_process_kill function
-
-$ ${bindir:=.}/process-kill ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [ 0.000000] (1:killer@Tremblay) Hello!
-> [ 0.000000] (2:victim@Fafard) Hello!
-> [ 0.000000] (2:victim@Fafard) Suspending myself
-> [ 10.000000] (1:killer@Tremblay) Resume victim
-> [ 10.000000] (1:killer@Tremblay) Kill victim
-> [ 10.000000] (1:killer@Tremblay) OK, goodbye now. I commit a suicide.
-> [ 10.000000] (0:maestro@) Simulation time 10