static int master(int argc, char *argv[]) { xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self()); msg_process_t process = NULL; MSG_process_sleep(1); xbt_swag_foreach(process, process_list) { XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process), MSG_process_get_name(process)); if (MSG_process_self_PID() != MSG_process_get_PID(process)) MSG_process_kill(process); }
/** Create a Java org.simgrid.msg.Process with the arguments and run it */ static int java_main(int argc, char *argv[]) { JNIEnv *env = get_current_thread_env(); simgrid::java::JavaContext* context = (simgrid::java::JavaContext*) SIMIX_context_self(); //Change the "." in class name for "/". xbt_str_subst(argv[0],'.','/',0); jclass class_Process = env->FindClass(argv[0]); xbt_str_subst(argv[0],'/','.',0); //Retrieve the methodID for the constructor xbt_assert((class_Process != nullptr), "Class not found (%s). The deployment file must use the fully qualified class name, including the package. The case is important.", argv[0]); jmethodID constructor_Process = env->GetMethodID(class_Process, "<init>", "(Lorg/simgrid/msg/Host;Ljava/lang/String;[Ljava/lang/String;)V"); xbt_assert((constructor_Process != nullptr), "Constructor not found for class %s. Is there a (Host, String ,String[]) constructor in your class ?", argv[0]); //Retrieve the name of the process. jstring jname = env->NewStringUTF(argv[0]); //Build the arguments jobjectArray args = (jobjectArray)env->NewObjectArray(argc - 1, env->FindClass("java/lang/String"), env->NewStringUTF("")); int i; for (i = 1; i < argc; i++) env->SetObjectArrayElement(args,i - 1, env->NewStringUTF(argv[i])); //Retrieve the host for the process. jstring jhostName = env->NewStringUTF(MSG_host_get_name(MSG_host_self())); jobject jhost = Java_org_simgrid_msg_Host_getByName(env, nullptr, jhostName); //creates the process jobject jprocess = env->NewObject(class_Process, constructor_Process, jhost, jname, args); xbt_assert((jprocess != nullptr), "Process allocation failed."); jprocess = env->NewGlobalRef(jprocess); //bind the process to the context msg_process_t process = MSG_process_self(); context->jprocess = jprocess; /* sets the PID and the PPID of the process */ env->SetIntField(jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process)); env->SetIntField(jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process)); jprocess_bind(jprocess, process, env); run_jprocess(env, context->jprocess); return 0; }
/** \ingroup m_process_management * \brief Return the PPID of the current process. * * This function returns the PID of the parent of the currently running #msg_process_t. */ int MSG_process_self_PPID() { return MSG_process_get_PPID(MSG_process_self()); }
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, jobject jprocess_arg, jobject jhostname) { jobject jprocess; /* the global reference to the java process instance */ jstring jname; /* the name of the java process instance */ const char *name; /* the C name of the process */ const char *hostname; msg_process_t process; /* the native process to create */ msg_host_t host; /* Where that process lives */ hostname = (*env)->GetStringUTFChars(env, jhostname, 0); /* get the name of the java process */ jname = jprocess_get_name(jprocess_arg, env); if (!jname) { jxbt_throw_null(env, xbt_strdup("Internal error: Process name cannot be NULL")); return; } /* bind/retrieve the msg host */ host = MSG_host_by_name(hostname); if (!(host)) { /* not bound */ jxbt_throw_host_not_found(env, hostname); return; } /* create a global java process instance */ jprocess = jprocess_new_global_ref(jprocess_arg, env); if (!jprocess) { jxbt_throw_jni(env, "Can't get a global ref to the java process"); return; } /* build the C name of the process */ name = (*env)->GetStringUTFChars(env, jname, 0); name = xbt_strdup(name); /* Retrieve the kill time from the process */ jdouble jkill = (*env)->GetDoubleField(env, jprocess, jprocess_field_Process_killTime); /* Actually build the MSG process */ process = MSG_process_create_with_environment(name, (xbt_main_func_t) jprocess, /*data*/ jprocess, host, /*argc, argv, properties*/ 0,NULL,NULL); MSG_process_set_kill_time(process, (double)jkill); /* bind the java process instance to the native process */ jprocess_bind(jprocess, process, env); /* release our reference to the process name (variable name becomes invalid) */ //FIXME : This line should be uncommented but with mac it doesn't work. BIG WARNING //(*env)->ReleaseStringUTFChars(env, jname, name); (*env)->ReleaseStringUTFChars(env, jhostname, hostname); /* sets the PID and the PPID of the process */ (*env)->SetIntField(env, jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process)); (*env)->SetIntField(env, jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process)); /* sets the Host of the process */ jobject jhost = Java_org_simgrid_msg_Host_getByName(env,NULL,jhostname); (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost); }