1 /* Copyright (c) 2010-2017. 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_test, "Messages specific for this msg example");
10 static int slave(int argc, char* argv[])
12 MSG_process_sleep(.5);
13 XBT_INFO("Slave started (PID:%d, PPID:%d)", MSG_process_self_PID(), MSG_process_self_PPID());
15 XBT_INFO("Plop i am %ssuspended", (MSG_process_is_suspended(MSG_process_self())) ? "" : "not ");
18 XBT_INFO("I'm done. See you!");
22 static int master(int argc, char* argv[])
25 xbt_dynar_t process_list = xbt_dynar_new(sizeof(msg_process_t), nullptr);
26 MSG_host_get_process_list(MSG_host_self(), process_list);
28 msg_process_t process = NULL;
30 xbt_dynar_foreach (process_list, cursor, process) {
31 XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process),
32 MSG_process_get_name(process));
33 if (MSG_process_self_PID() != MSG_process_get_PID(process))
34 MSG_process_kill(process);
36 xbt_dynar_free(&process_list);
38 process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
41 XBT_INFO("Suspend Process(pid=%d)", MSG_process_get_PID(process));
42 MSG_process_suspend(process);
44 XBT_INFO("Process(pid=%d) is %ssuspended", MSG_process_get_PID(process),
45 (MSG_process_is_suspended(process)) ? "" : "not ");
48 XBT_INFO("Resume Process(pid=%d)", MSG_process_get_PID(process));
49 MSG_process_resume(process);
51 XBT_INFO("Process(pid=%d) is %ssuspended", MSG_process_get_PID(process),
52 (MSG_process_is_suspended(process)) ? "" : "not ");
54 MSG_process_kill(process);
56 XBT_INFO("Goodbye now!");
60 int main(int argc, char* argv[])
62 MSG_init(&argc, argv);
63 xbt_assert(argc == 2, "Usage: %s platform_file\n\t Example: %s msg_platform.xml\n", argv[0], argv[0]);
65 MSG_create_environment(argv[1]);
67 MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay"));
68 MSG_process_create("slave", slave, NULL, MSG_get_host_by_name("Tremblay"));
70 msg_error_t res = MSG_main();
72 XBT_INFO("Simulation time %g", MSG_get_clock());