-   Linux - Newbie (
-   -   Shell GET PID (

Scarrez 11-16-2012 09:05 AM


I'm writing a shell script call "" and in it I have it executing a Java file in a screen.

"screen -A -m -d -S mine java -jar /servers/minecraft.jar nogui"

I'm executing this from a C++ application I'm writing using system() and I want to get the PID from the actual minecraft server and return it to the C++ application.

I know you can use "exit" in shell but how do I actually acquire the PID from the screen I'm starting??

Using "echo $$" gets the PID of the shell file but not the java file which is what I'm interested in.


unSpawn 11-16-2012 09:17 AM


pgrep -f "java -jar /servers/minecraft.jar nogui"

Scarrez 11-16-2012 10:16 AM

Thanks, works like a treat, might be a long shot but I'm trying to return this to a C++ program, for instance...


int i = system("pgrep -f 'java -jar /servers/minecraft.jar nogui'");
it just returns 0 though, is there another function I can use as an alternative to system().


linosaurusroot 11-16-2012 10:53 AM

popen() is like system where you want to do input or output.

Scarrez 11-16-2012 02:27 PM

Thanks, will check out popen()

All times are GMT -5. The time now is 10:18 AM.