LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell GET PID (https://www.linuxquestions.org/questions/linux-newbie-8/shell-get-pid-4175437430/)

Scarrez 11-16-2012 09:05 AM

Shell GET PID
 
Hi,

I'm writing a shell script call "start.sh" 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.

Thanks
Scarrez

unSpawn 11-16-2012 09:17 AM

Code:

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...

Code:

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().


Thanks

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.