1 /* Copyright (c) 2007-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. */
6 #include "simgrid/msg.h"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_process_kill, "Messages specific for this msg example");
10 static int victim_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
13 XBT_INFO("Suspending myself");
14 MSG_process_suspend(MSG_process_self()); /* - First suspend itself */
15 XBT_INFO("OK, OK. Let's work"); /* - Then is resumed and start to execute a task */
16 MSG_task_execute(MSG_task_create("work", 1e9, 0, NULL));
17 XBT_INFO("Bye!"); /* - But will never reach the end of it */
21 static int killer(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
23 XBT_INFO("Hello!"); /* - First start a victim process */
24 msg_process_t victim = MSG_process_create("victim", victim_fun, NULL, MSG_host_by_name("Fafard"));
25 MSG_process_sleep(10.0);
27 XBT_INFO("Resume victim"); /* - Resume it from its suspended state */
28 MSG_process_resume(victim);
30 XBT_INFO("Kill victim"); /* - and then kill it */
31 MSG_process_kill(victim);
33 XBT_INFO("OK, goodbye now. I commit a suicide.");
34 MSG_process_kill(MSG_process_self());
36 XBT_INFO("This line will never get displayed: I'm already dead since the previous line.");
40 int main(int argc, char* argv[])
42 MSG_init(&argc, argv);
43 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
45 MSG_create_environment(argv[1]); /* - Load the platform description */
46 /* - Create and deploy killer process, that will create the victim process */
47 MSG_process_create("killer", killer, NULL, MSG_host_by_name("Tremblay"));
49 msg_error_t res = MSG_main(); /* - Run the simulation */
51 XBT_INFO("Simulation time %g", MSG_get_clock());