1 /* Copyright (c) 2006-2015. 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 #ifndef SIMGRID_S4U_PROCESS_HPP
7 #define SIMGRID_S4U_PROCESS_HPP
9 #include "simgrid/simix.h"
16 /** @brief Simulation Agent
18 * A process may be defined as a code executing in a location (host).
20 * All processes should be started from the XML deployment file (using the @link{s4u::Engine::loadDeployment()}),
21 * even if you can also start new processes directly.
22 * Separating the deployment in the XML from the logic in the code is a good habit as it makes your simulation easier
23 * to adapt to new settings.
25 * The code that you define for a given process should be placed in the main method that is virtual.
26 * For example, a Worker process should be declared as follows:
29 * #include "s4u/process.hpp"
31 * class Worker : simgrid::s4u::Process {
33 * int main(int argc, char **argv) {
34 * printf("Hello s4u");
42 Process(const char*procname, s4u::Host *host, int argc, char **argv);
43 Process(const char*procname, s4u::Host *host, int argc, char **argv, double killTime);
46 /** The main method of your agent */
47 virtual int main(int argc, char **argv)=0;
49 /** The process that is currently running */
50 static Process *current();
51 /** Retrieves the process that have the given PID (or NULL if not existing) */
52 static Process *byPid(int pid);
54 /** Retrieves the name of that process */
56 /** Retrieves the host on which that process is running */
58 /** Retrieves the PID of that process */
61 /** If set to true, the process will automatically restart when its host reboots */
62 void setAutoRestart(bool autorestart);
63 /** Sets the time at which that process should be killed */
64 void setKillTime(double time);
65 /** Retrieves the time at which that process will be killed (or -1 if not set) */
68 /** Ask kindly to all processes to die. Only the issuer will survive. */
69 static void killAll();
70 /** Ask the process to die.
72 * It will only notice your request when doing a simcall next time (a communication or similar).
73 * SimGrid sometimes have issues when you kill processes that are currently communicating and such. We are working on it to fix the issues.
77 /** Block the process sleeping for that amount of seconds (may throws hostFailure) */
78 void sleep(double duration);
80 /** Block the process, computing the given amount of flops */
81 void execute(double flop);
83 /** Block the process until it gets a message from the given mailbox */
84 //void* recv(const char *mailbox);
86 /** Block the process until it gets a string message (to be freed after use) from the given mailbox */
87 char *recvstr(const char* mailbox);
89 /** Block the process until it delivers a string message (that will be copied) to the given mailbox */
90 void sendstr(const char*mailbox, const char*msg);
93 smx_process_t getInferior() {return p_smx_process;}
95 smx_process_t p_smx_process;
97 }} // namespace simgrid::s4u
99 #endif /* SIMGRID_S4U_PROCESS_HPP */
103 public abstract class Process implements Runnable {
104 /** Suspends the process. See {@link #resume()} to resume it afterward */
105 public native void suspend();
106 /** Resume a process that was suspended by {@link #suspend()}. */
107 public native void resume();
108 /** Tests if a process is suspended. */
109 public native boolean isSuspended();
112 * Returns the value of a given process property.
114 public native String getProperty(String name);
118 * Migrates a process to another host.
120 * @param host The host where to migrate the process.
123 public native void migrate(Host host);
125 public native void exit();
127 * This static method returns the current amount of processes running
129 * @return The count of the running processes
131 public native static int getCount();