Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix mpi bcast flattree-pipeline collective
[simgrid.git] / teshsuite / msg / pid.c
1 /* Copyright (c) 2009, 2010. 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 "msg/msg.h"
8 #include "xbt/sysdep.h"        
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
11                              "Messages specific for this msg example");
12 const char* mailbox = "mailbox";
13 #define task_comp_size 1000
14 #define task_comm_size 100000
15
16 static int onexit(void* data){
17   XBT_INFO("Process \"%d\" killed.", *((int*)data));
18   return 0;
19 }
20
21 static int sendpid(int argc, char *argv[])
22 {
23   int pid = MSG_process_self_PID();
24   MSG_process_on_exit(onexit, &pid);  
25   msg_task_t task = MSG_task_create("pid", task_comp_size, task_comm_size, &pid);
26   XBT_INFO("Sending pid of \"%d\".", pid);
27   MSG_task_send(task, mailbox);
28   XBT_INFO("Send of pid \"%d\" done.", pid);
29   MSG_process_suspend(MSG_process_self());
30   return 0;
31 }
32
33 static int killall(int argc, char *argv[]){
34   msg_task_t task = NULL;
35   _XBT_GNUC_UNUSED int res;
36   int i;
37   for (i=0; i<3;i++) {
38     res = MSG_task_receive(&(task), mailbox);
39     int pid = *(int*)MSG_task_get_data(task);
40     MSG_task_destroy(task);
41     XBT_INFO("Killing process \"%d\".", pid);
42     MSG_process_kill(MSG_process_from_PID(pid));
43     task = NULL;
44   }
45   return 0;
46 }
47
48 /** Main function */
49 int main(int argc, char *argv[])
50 {
51   msg_error_t res = MSG_OK;
52
53   MSG_init(&argc, argv);
54
55   /*   Application deployment */
56   MSG_function_register("sendpid", &sendpid);
57   MSG_function_register("killall", &killall);
58
59   MSG_process_killall(atoi(argv[3]));
60
61   MSG_create_environment(argv[1]);
62   MSG_launch_application(argv[2]);
63   res = MSG_main();
64
65   if (res == MSG_OK)
66     return 0;
67   else
68     return 1;
69 }