1 /* Copyright (c) 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_process_daemon, "Messages specific for this msg example");
10 /* The worker process, working for a while before leaving */
11 static int worker_process(int argc, char* argv[])
13 XBT_INFO("Let's do some work (for 10 sec on Boivin).");
14 msg_task_t task = MSG_task_create("easy work", 980.95e6, 0, NULL);
15 MSG_task_execute(task);
16 MSG_task_destroy(task);
18 XBT_INFO("I'm done now. I leave even if it makes the daemon die.");
22 /* The daemon, displaying a message every 3 seconds until all other processes stop */
23 static int daemon_process(int argc, char* argv[])
25 MSG_process_daemonize(MSG_process_self());
28 XBT_INFO("Hello from the infinite loop");
29 MSG_process_sleep(3.0);
32 XBT_INFO("I will never reach that point: daemons are killed when regular processes are done");
36 int main(int argc, char* argv[])
38 MSG_init(&argc, argv);
39 xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
41 MSG_create_environment(argv[1]);
42 xbt_dynar_t hosts = MSG_hosts_as_dynar();
43 MSG_process_create("worker", worker_process, NULL, xbt_dynar_getfirst_as(hosts, msg_host_t));
44 MSG_process_create("daemon", daemon_process, NULL, xbt_dynar_getlast_as(hosts, msg_host_t));
45 xbt_dynar_free(&hosts);
46 msg_error_t res = MSG_main();