Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Further reorganize the MSG examples' documentation
[simgrid.git] / examples / msg / process-kill / process-kill.c
1 /* Copyright (c) 2007, 2009-2016. The SimGrid Team. All rights reserved.    */
2
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. */
5
6 #include "simgrid/msg.h"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_process_kill, "Messages specific for this msg example");
9
10 static int victim(int argc, char *argv[])
11 {
12   XBT_INFO("Hello!");
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 */
18   return 0;
19 }
20
21 static int killer(int argc, char *argv[])
22 {
23   XBT_INFO("Hello!");         /* - First start a victim process */
24   msg_process_t poor_victim = MSG_process_create("victim", victim, NULL, MSG_host_by_name("Fafard"));
25   MSG_process_sleep(10.0);
26
27   XBT_INFO("Resume process"); /* - Resume it from its suspended state */
28   MSG_process_resume(poor_victim);
29
30   XBT_INFO("Kill process");   /* - and then kill it */
31   MSG_process_kill(poor_victim);
32
33   XBT_INFO("OK, goodbye now.");
34   return 0;
35 }
36
37 int main(int argc, char *argv[])
38 {
39   msg_error_t res = MSG_OK;
40
41   MSG_init(&argc, argv);
42   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
43
44   MSG_create_environment(argv[1]);   /* - Load the platform description */
45   /* - Create and deploy killer process, that will create the victim process  */
46   MSG_process_create("killer", killer, NULL, MSG_host_by_name("Tremblay"));
47
48   res = MSG_main();                 /* - Run the simulation */
49
50   XBT_INFO("Simulation time %g", MSG_get_clock());
51   return res != MSG_OK;
52 }