Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e29a615adf68558d2fee74849198f55d3b3ffbb0
[simgrid.git] / teshsuite / msg / process / process.c
1 /* Copyright (c) 2010-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 slave(int argc, char *argv[])
12 {
13   MSG_process_sleep(.5);
14   XBT_INFO("Slave started (PID:%d, PPID:%d)", MSG_process_self_PID(), MSG_process_self_PPID());
15   while(1){
16     XBT_INFO("Plop i am %ssuspended", (MSG_process_is_suspended(MSG_process_self())) ? "" : "not ");
17     MSG_process_sleep(1);
18   }
19   XBT_INFO("I'm done. See you!");
20   return 0;
21 }
22
23 static int master(int argc, char *argv[])
24 {
25   xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self());
26   msg_process_t process = NULL;
27   MSG_process_sleep(1);
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);
33   }
34   process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
35   MSG_process_sleep(2);
36
37   XBT_INFO("Suspend Process(pid=%d)", MSG_process_get_PID(process));
38   MSG_process_suspend(process);
39
40   XBT_INFO("Process(pid=%d) is %ssuspended", MSG_process_get_PID(process),
41            (MSG_process_is_suspended(process)) ? "" : "not ");
42   MSG_process_sleep(2);
43
44   XBT_INFO("Resume Process(pid=%d)", MSG_process_get_PID(process));
45   MSG_process_resume(process);
46
47   XBT_INFO("Process(pid=%d) is %ssuspended", MSG_process_get_PID(process),
48            (MSG_process_is_suspended(process)) ? "" : "not ");
49   MSG_process_sleep(2);
50   MSG_process_kill(process);
51
52   XBT_INFO("Goodbye now!");
53   return 0;
54 }
55
56 int main(int argc, char *argv[])
57 {
58   msg_error_t res;
59
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]);
63
64   MSG_create_environment(argv[1]);
65
66   MSG_function_register("master", master);
67   MSG_function_register("slave", slave);
68
69   MSG_launch_application(argv[2]);
70
71   res = MSG_main();
72
73   XBT_INFO("Simulation time %g", MSG_get_clock());
74
75   return res != MSG_OK;
76 }