Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mv msg/msg.h simgrid/msg.h
[simgrid.git] / examples / msg / masterslave / masterslave_kill.c
1 /* Copyright (c) 2007, 2009-2014. 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"        /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
8 #include "xbt/sysdep.h"         /* calloc */
9
10 /* Create a log channel to have nice outputs. */
11 #include "xbt/log.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
13                              "Messages specific for this msg example");
14
15 /** Lazy guy function. This process suspends itself asap.  */
16 static int slave(int argc, char *argv[])
17 {
18   XBT_INFO("Hello!");
19   XBT_INFO("Suspending myself");
20   MSG_process_suspend(MSG_process_self());
21   XBT_INFO("OK, OK. Let's work");
22   MSG_task_execute(MSG_task_create("toto", 1e9, 0, NULL));
23   XBT_INFO("Bye!");
24   return 0;
25 }                               /* end_of_lazy_guy */
26
27 static int master(int argc, char *argv[])
28 {
29   msg_process_t bob = NULL;
30
31   XBT_INFO("Hello!");
32   bob = MSG_process_create("slave", slave, NULL, MSG_get_host_by_name("Fafard"));
33   MSG_process_sleep(10.0);
34
35   XBT_INFO("Resume process");
36   MSG_process_resume(bob);
37
38   XBT_INFO("Kill process");
39   MSG_process_kill(bob);
40
41   XBT_INFO("OK, goodbye now.");
42   return 0;
43 }                               /* end_of_dram_master */
44
45 /** Test function */
46 static msg_error_t test_all(const char *platform_file,
47                             const char *application_file)
48 {
49   msg_error_t res = MSG_OK;
50
51   MSG_create_environment(platform_file);
52   MSG_function_register("master", master);
53   MSG_function_register("slave", slave);
54   MSG_launch_application(application_file);
55
56   res = MSG_main();
57
58   XBT_INFO("Simulation time %g", MSG_get_clock());
59   return res;
60 }                               /* end_of_test_all */
61
62
63 /** Main function */
64 int main(int argc, char *argv[])
65 {
66   msg_error_t res = MSG_OK;
67
68   MSG_init(&argc, argv);
69   if (argc < 3) {
70     XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
71     XBT_CRITICAL("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
72               argv[0]);
73     exit(1);
74   }
75   test_all(argv[1], argv[2]);
76
77   if (res == MSG_OK)
78     return 0;
79   else
80     return 1;
81 }                               /* end_of_main */