Find process id (pid) of dedicated server instance

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

This post demonstrates how to retrieve the pid of a dedicated JBoss application server, running parallel on a linux server with other application servers. The combination of ps, grep and awk allows a operator friendly output.

Searching for JBoss server with name dev

ps -ef | grep 'dev'

Options explained

  • -e = Display information about other users’ processes, including those without controlling terminals.
  • -f = Display the uid, pid, parent pid, recent CPU usage, process start time, controlling tty, elapsed CPU usage, and the associated command.

The output will also contain the grep command. To avoid that, we can exclude with

grep '[d]ev'

Using awk to print a friendly output. The field numbers may vary depending on your output.

tan@cinhtau:~> ps -ef | grep '[d]ev' | awk '{ print $2 " " $8 " " $9 " " $NF}'
13606 /usr/lib/jvm/jdk1.8.0_51/bin/java -D[Server:dev] org.jboss.as.server

awk explained:

  • $2 contains pid (the information I want)
  • $8 contains command
  • $9 contains argument (the server argument)
  • $NF print last field (the awk builtin variable NF gives you the total number of fields in a record)

The given pid 13606 is used to access the JVM with a cli (command line interface) for jmx. The purpose is Monitoring and Management Using JMX Technology.

The Java virtual machine (Java VM ) has built-in instrumentation that enables you to monitor and manage it using the Java Management Extensions (JMX) technology. These built-in management utilities are often referred to as out-of-the-box management tools for the Java VM. You can also monitor any appropriately instrumented applications using the JMX API.

Java SE Documentation cjmx is a command line JMX client intended to be used when graphical tools (e.g., JConsole, VisualVM) are unavailable.

java -jar path/to/cjmx.jar [PID]
Please remember the terms for blog comments.