File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Expression to get Tomcat pid? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Expression to get Tomcat pid?" Watch "Expression to get Tomcat pid?" New topic
Author

Expression to get Tomcat pid?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

I'm using Tomcat 6.0.26 for Mac 10.6.3. Does anyone know a shell script expression to get the Tomcat PID and put it in a shell variable? This isn't working for me ...



I'm starting Tomcat using the provided startup.sh script.

Thanks, - Dave
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

You can use this one


Regards, Rene Larsen
Dropbox Invite
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

Take a look at the catalina.sh script in Tomcat. There's an option labelled CATALINA_PID. In Unix/Linux, the PIDfile holds the PID value for the benefit of the system control scripts.


Customer surveys are for companies who didn't pay proper attention to begin with.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Rene,

Thanks for your reply but the command produced no results. In fact, here is what "ps -axe | grep tomcat" produced ...



ps -ef | grep java produces something a little more interesting ...





Tim,

I looked at catalina.sh and saw references to CATALINA_PID, but I wasn't able to find anywhere where the variable was exported, and indeed, when I open a shell and run "echo $CATALINA_PID", it comes up empty. Do I need to edit catalina.sh in some way? - Dave

Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

I'm using a Mac as well, but "ps -ef | grep java" result in

But when I'm using "ps -axe | grep java" i'm getting

and when using the complete syntax I posted earlier, I'm getting
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

OK - I'm using iTerm as the Terminal - and here -axe is working because the shell is diffrent from Apples Terminal Application - where the flags -ef is working.

If you use the command below you should get the pid.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
How are you starting Tomcat? I'm using bash shell script and this command



doesn't produce anything, even though Tomcat is definitely running. - Dave
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

In your case you need to use Tomcat (with capital letter)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

The CATALINA_PID in the catalina.sh is not an export. That's why you can't find it. It's the location of a FILE that the pid will be stored into. You can access it like so:



One advantage of that approach is that other processes can get the PID easily.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Tim Holloway wrote:The CATALINA_PID in the catalina.sh is not an export. That's why you can't find it. It's the location of a FILE that the pid will be stored into. You can access it like so:



One advantage of that approach is that other processes can get the PID easily.

Where is this PID file located - I can't find it when the server is running???

That's why I use the shell command my self.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

The PID file is located wherever you tell the catalina script to put it. CATALINA_PID is an input variable, not an output. You supply the path/file and tomcat writes its PID number a single line of text to that file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Expression to get Tomcat pid?