Monday, August 1, 2011

Tomcat printing catalina pid

If you are hosting more then one tomcats on a physical box in production then lot of times you might want to see the process id of running instance. We dump jstacks/top command output in a folder every 5 minutes and this helps in correlating it. Here is a sample code to dump tomcat pid.

 public String getJvmProcessid() throws IOException {
  String pid = null;
  File pidFile = new File(System.getenv("CATALINA_PID"));
  if(pidFile.exists()) {
   FileInputStream fin = new FileInputStream(pidFile);
   List lines = IOUtils.readLines(fin);
   fin.close();
   pid = StringUtils.join(lines.toArray());
  }
  return pid;
 }

No comments:

Post a Comment