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"
17 /** @brief Simulation Agent
19 * A process may be defined as a code executing in a location (host).
21 * All processes should be started from the XML deployment file (using the @link{s4u::Engine::loadDeployment()}),
22 * even if you can also start new processes directly.
23 * Separating the deployment in the XML from the logic in the code is a good habit as it makes your simulation easier
24 * to adapt to new settings.
26 * The code that you define for a given process should be placed in the main method that is virtual.
27 * For example, a Worker process should be declared as follows:
30 * #include "s4u/process.hpp"
32 * class Worker : simgrid::s4u::Process {
34 * int main(int argc, char **argv) {
35 * printf("Hello s4u");
43 Process(const char*procname, s4u::Host *host, int argc, char **argv);
44 Process(const char*procname, s4u::Host *host, int argc, char **argv, double killTime);
47 /** The main method of your agent */
48 virtual int main(int argc, char **argv)=0;
50 /** The process that is currently running */
51 static Process *current();
52 /** Retrieves the process that have the given PID (or NULL if not existing) */
53 static Process *byPid(int pid);
55 /** Retrieves the name of that process */
57 /** Retrieves the host on which that process is running */
59 /** Retrieves the PID of that process */
62 /** If set to true, the process will automatically restart when its host reboots */
63 void setAutoRestart(bool autorestart);
64 /** Sets the time at which that process should be killed */
65 void setKillTime(double time);
66 /** Retrieves the time at which that process will be killed (or -1 if not set) */
69 /** Ask kindly to all processes to die. Only the issuer will survive. */
70 static void killAll();
71 /** Ask the process to die.
73 * It will only notice your request when doing a simcall next time (a communication or similar).
74 * SimGrid sometimes have issues when you kill processes that are currently communicating and such. We are working on it to fix the issues.
78 /** Block the process sleeping for that amount of seconds (may throws hostFailure) */
79 void sleep(double duration);
81 /** Block the process, computing the given amount of flops */
82 void execute(double flop);
84 /** Block the process until it gets a message from the given mailbox */
85 //void* recv(const char *mailbox);
87 /** Block the process until it gets a string message (to be freed after use) from the given mailbox */
88 char *recvstr(Channel &chan);
90 /** Block the process until it delivers a string message (that will be copied) to the given mailbox */
91 void sendstr(Channel &chan, const char*msg);
94 smx_process_t getInferior() {return p_smx_process;}
96 smx_process_t p_smx_process;
98 }} // namespace simgrid::s4u
100 #endif /* SIMGRID_S4U_PROCESS_HPP */
104 public abstract class Process implements Runnable {
105 /** Suspends the process. See {@link #resume()} to resume it afterward */
106 public native void suspend();
107 /** Resume a process that was suspended by {@link #suspend()}. */
108 public native void resume();
109 /** Tests if a process is suspended. */
110 public native boolean isSuspended();
113 * Returns the value of a given process property.
115 public native String getProperty(String name);
119 * Migrates a process to another host.
121 * @param host The host where to migrate the process.
124 public native void migrate(Host host);
126 public native void exit();
128 * This static method returns the current amount of processes running
130 * @return The count of the running processes
132 public native static int getCount();