Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
have uniform log format for the same example
[simgrid.git] / examples / msg / process-kill / process-kill.c
1 /* Copyright (c) 2007, 2009-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "simgrid/msg.h"
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
10
11 static int victim(int argc, char *argv[])
12 {
13   XBT_INFO("Hello!");
14   XBT_INFO("Suspending myself");
15   MSG_process_suspend(MSG_process_self());
16   XBT_INFO("OK, OK. Let's work");
17   MSG_task_execute(MSG_task_create("work", 1e9, 0, NULL));
18   XBT_INFO("Bye!");
19   return 0;
20 }
21
22 static int killer(int argc, char *argv[])
23 {
24   msg_process_t poor_victim = NULL;
25
26   XBT_INFO("Hello!");
27   poor_victim = MSG_process_create("victim", victim, NULL, MSG_host_by_name("Fafard"));
28   MSG_process_sleep(10.0);
29
30   XBT_INFO("Resume process");
31   MSG_process_resume(poor_victim);
32
33   XBT_INFO("Kill process");
34   MSG_process_kill(poor_victim);
35
36   XBT_INFO("OK, goodbye now.");
37   return 0;
38 }
39
40 int main(int argc, char *argv[])
41 {
42   msg_error_t res = MSG_OK;
43
44   MSG_init(&argc, argv);
45   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
46
47   MSG_create_environment(argv[1]);
48
49   MSG_function_register("killer", killer);
50   MSG_function_register("victim", victim);
51   MSG_process_create("killer", killer, NULL, MSG_host_by_name("Tremblay"));
52
53   res = MSG_main();
54
55   XBT_INFO("Simulation time %g", MSG_get_clock());
56
57   return res != MSG_OK;
58 }