How do I run a process from a C++ program and obtain its PID? Right now I am doing in a "parallel" thread:
system("ampl method.run");
and into the main function (after running the thread mentioned before):
1 2
sleep(5); //Just to be sure that the thread is executing the ampl command
system("ps -Ac| grep ampl | awk '{print $1}' > ~/AMPL_PID.txt");
This doesn't work. The main program hangs in the "system" function while the thread continues to execute. Once I manually kill the ampl process in the thread, the main program continues and writes the system("ps -Ac...") output to the desired location.
I need to be able to obtain the ampl command PID in order to later kill it (if necessary). Any ideas how to make this work or how to do this?