1 /* Copyright (c) 2009, 2010. 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. */
8 #include "xbt/sysdep.h"
10 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
11 "Messages specific for this msg example");
12 char* mailbox = "mailbox";
13 #define task_comp_size 1000
14 #define task_comm_size 100000
16 int onexit(void* data){
17 XBT_INFO("Process \"%d\" killed.", *((int*)data));
20 int sendpid(int argc, char *argv[])
22 int pid = MSG_process_self_PID();
23 MSG_process_on_exit(onexit, &pid);
24 msg_task_t task = MSG_task_create("pid", task_comp_size, task_comm_size, &pid);
25 XBT_INFO("Sending pid of \"%d\".", pid);
26 MSG_task_send(task, mailbox);
27 XBT_INFO("Send of pid \"%d\" done.", pid);
28 MSG_process_suspend(MSG_process_self());
31 int killall(int argc, char *argv[]){
32 msg_task_t task = NULL;
33 _XBT_GNUC_UNUSED int res;
36 res = MSG_task_receive(&(task), mailbox);
37 int pid = *((int*)MSG_task_get_data(task));
38 XBT_INFO("Killing process \"%d\".", pid);
39 MSG_process_kill(MSG_process_from_PID(pid));
45 int main(int argc, char *argv[])
47 msg_error_t res = MSG_OK;
49 MSG_init(&argc, argv);
51 /* Application deployment */
52 MSG_function_register("sendpid", &sendpid);
53 MSG_function_register("killall", &killall);
55 MSG_process_killall(atoi(argv[2]));
57 MSG_create_environment(argv[1]);
58 MSG_launch_application(argv[1]);