LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-16-2012, 09:05 AM   #1
Scarrez
LQ Newbie
 
Registered: Nov 2012
Posts: 7

Rep: Reputation: Disabled
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
 
Old 11-16-2012, 09:17 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Code:
pgrep -f "java -jar /servers/minecraft.jar nogui"
 
Old 11-16-2012, 10:16 AM   #3
Scarrez
LQ Newbie
 
Registered: Nov 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
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
 
Old 11-16-2012, 10:53 AM   #4
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
popen() is like system where you want to do input or output.
 
Old 11-16-2012, 02:27 PM   #5
Scarrez
LQ Newbie
 
Registered: Nov 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks, will check out popen()
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to find the PID of Shell scripts ? splinux Linux - General 15 05-05-2012 01:31 PM
question on PID's and Executing a shell script jonhanna Linux - Newbie 3 12-30-2008 12:39 PM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
Find parent PID in shell script ? bugmenot Programming 7 02-07-2007 12:09 PM
obtaining PID of shell script sanjith11 Programming 3 07-14-2004 10:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration