Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9f1099d9eb9159c88e950c079160e774e32dca9d
[simgrid.git] / teshsuite / s4u / pid / pid.cpp
1 /* Copyright (c) 2009-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/s4u.hpp"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this msg example");
9
10 static void sendpid()
11 {
12   simgrid::s4u::Mailbox* mailbox   = simgrid::s4u::Mailbox::by_name("mailbox");
13   int pid                          = simgrid::s4u::this_actor::get_pid();
14   double comm_size                 = 100000;
15   simgrid::s4u::this_actor::on_exit([pid](bool /*failed*/) { XBT_INFO("Process \"%d\" killed.", pid); });
16
17   XBT_INFO("Sending pid of \"%d\".", pid);
18   mailbox->put(&pid, comm_size);
19   XBT_INFO("Send of pid \"%d\" done.", pid);
20
21   simgrid::s4u::this_actor::suspend();
22 }
23
24 static void killall()
25 {
26   simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("mailbox");
27   for (int i = 0; i < 3; i++) {
28     int* pid = static_cast<int*>(mailbox->get());
29     XBT_INFO("Killing process \"%d\".", *pid);
30     simgrid::s4u::Actor::by_pid(*pid)->kill();
31   }
32 }
33
34 int main(int argc, char* argv[])
35 {
36   simgrid::s4u::Engine e(&argc, argv);
37   e.load_platform(argv[1]);
38
39   simgrid::s4u::Actor::kill_all();
40
41   simgrid::s4u::Actor::create("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid);
42   simgrid::s4u::Actor::create("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid);
43   simgrid::s4u::Actor::create("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid);
44   simgrid::s4u::Actor::create("killall", simgrid::s4u::Host::by_name("Tremblay"), killall);
45
46   e.run();
47
48   return 0;
49 }