+/**
+ * \brief Internal function to create a process.
+ *
+ * This function actually creates the process.
+ * It may be called when a SIMCALL_PROCESS_CREATE simcall occurs,
+ * or directly for SIMIX internal purposes. The sure thing is that it's called from maestro context.
+ *
+ * \return the process created
+ */
+void SIMIX_process_create(smx_process_t *process,
+ const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ double kill_time,
+ int argc, char **argv,
+ xbt_dict_t properties) {
+
+ *process = NULL;
+ smx_host_t host = SIMIX_host_get_by_name(hostname);
+
+ XBT_DEBUG("Start process %s on host %s", name, hostname);
+
+ if (!SIMIX_host_get_state(host)) {
+ XBT_WARN("Cannot launch process '%s' on failed host '%s'", name,
+ hostname);
+ }
+ else {
+ *process = xbt_new0(s_smx_process_t, 1);
+
+ xbt_assert(((code != NULL) && (host != NULL)), "Invalid parameters");
+
+ /* Process data */
+ (*process)->pid = simix_process_maxpid++;
+ (*process)->name = xbt_strdup(name);
+ (*process)->smx_host = host;
+ (*process)->data = data;
+ (*process)->comms = xbt_fifo_new();
+ (*process)->simcall.issuer = *process;
+
+ XBT_VERB("Create context %s", (*process)->name);
+ (*process)->context = SIMIX_context_new(code, argc, argv,
+ simix_global->cleanup_process_function, *process);
+
+ (*process)->running_ctx = xbt_new(xbt_running_ctx_t, 1);
+ XBT_RUNNING_CTX_INITIALIZE((*process)->running_ctx);
+
+ /* Add properties */
+ (*process)->properties = properties;
+
+ /* Add the process to it's host process list */
+ xbt_swag_insert(*process, host->process_list);
+
+ XBT_DEBUG("Start context '%s'", (*process)->name);
+
+ /* Build the dynars for the on_exit functions */
+ (*process)->on_exit_fun = xbt_dynar_new(sizeof(int_f_pvoid_t),NULL);
+ (*process)->on_exit_args = xbt_dynar_new(sizeof(void*),NULL);
+ /* Now insert it in the global process list and in the process to run list */
+ xbt_swag_insert(*process, simix_global->process_list);
+ XBT_DEBUG("Inserting %s(%s) in the to_run list", (*process)->name, host->name);
+ xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, *process);
+ }
+
+ if (kill_time > SIMIX_get_clock()) {
+ if (simix_global->kill_process_function) {
+ XBT_DEBUG("Process %s(%s) will be kill at time %f", (*process)->name,
+ (*process)->smx_host->name, kill_time);
+ SIMIX_timer_set(kill_time, simix_global->kill_process_function, *process);
+ }
+ }
+}
+
+/**
+ * \brief Executes the processes from simix_global->process_to_run.