1 /* Copyright (c) 2010-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid/msg.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
11 static int slave(int argc, char *argv[])
13 MSG_process_sleep(.5);
14 XBT_INFO("Slave started (PID:%d, PPID:%d)", MSG_process_self_PID(), MSG_process_self_PPID());
16 XBT_INFO("Plop i am %ssuspended", (MSG_process_is_suspended(MSG_process_self())) ? "" : "not ");
19 XBT_INFO("I'm done. See you!");
23 static int master(int argc, char *argv[])
25 xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self());
26 msg_process_t process = NULL;
28 xbt_swag_foreach(process, process_list) {
29 XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process),
30 MSG_process_get_name(process));
31 if (MSG_process_self_PID() != MSG_process_get_PID(process))
32 MSG_process_kill(process);
34 process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
37 XBT_INFO("Suspend Process(pid=%d)", MSG_process_get_PID(process));
38 MSG_process_suspend(process);
40 XBT_INFO("Process(pid=%d) is %ssuspended", MSG_process_get_PID(process),
41 (MSG_process_is_suspended(process)) ? "" : "not ");
44 XBT_INFO("Resume Process(pid=%d)", MSG_process_get_PID(process));
45 MSG_process_resume(process);
47 XBT_INFO("Process(pid=%d) is %ssuspended", MSG_process_get_PID(process),
48 (MSG_process_is_suspended(process)) ? "" : "not ");
50 MSG_process_kill(process);
52 XBT_INFO("Goodbye now!");
56 int main(int argc, char *argv[])
60 MSG_init(&argc, argv);
61 xbt_assert(argc == 3, "Usage: %s platform_file deployment_file\n"
62 "\n Example: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
64 MSG_create_environment(argv[1]);
66 MSG_function_register("master", master);
67 MSG_function_register("slave", slave);
69 MSG_launch_application(argv[2]);
73 XBT_INFO("Simulation time %g", MSG_get_clock());