Examining process information

The kernel provides useful process and environment information. These commands can be used to view this information.

The ps command

On Linux®, Java™ threads are implemented as system threads and might be visible in the process table, depending on the Linux distribution.

Running the ps command gives you a snapshot of the current processes. The ps command gets its information from the /proc file system. Here is an example of using ps:

ps -efwH

UID  PID  PPID  C STIME TTY   TIME        CMD
cass 1234 1231  0 Aug07  ?    00:00:00    /bin/bash
cass 1555 1234  0 Aug07  ?    00:00:02    java app
cass 1556 1555  0 Aug07  ?    00:00:00    java app
cass 1557 1556  0 Aug07  ?    00:00:00    java app
cass 1558 1556  0 Aug07  ?    00:00:00    java app
cass 1559 1556  0 Aug07  ?    00:00:00    java app
cass 1560 1556  0 Aug07  ?    00:00:00    java app    	   
e
Specifies to select all processes.
f
Ensures that a full listing is provided.
l
Displays in long format.
m
Shows threads if they are not shown by default.
w
An output modifier that ensures a wide output.
H
Useful when you are interested in Java threads because it displays a hierarchical listing. With a hierarchical display, you can determine which process is the primordial thread, which is the thread manager, and which are child threads. In the previous example, process 1555 is the primordial thread, while process 1556 is the thread manager. All the child processes have a parent process ID pointing to the thread manager.

The top command

The top command displays the most CPU-intensive or memory-intensive processes in real time. It provides an interactive interface for manipulation of processes and allows sorting by different criteria, such as CPU usage or memory usage. Press h while running top to see all the available interactive commands.

The top command displays several fields of information for each process. The process field shows the total number of processes that are running, but breaks down the information into tasks that are running, sleeping, stopped, or undead. In addition to displaying PID, PPID, and UID, the top command displays information about memory usage and swap space. The mem field shows statistics on memory usage, including available memory, free memory, used memory, shared memory, and memory used for buffers. The swap field shows total swap space, available swap space, and used swap space.

The vmstat command

The vmstat command reports virtual storage statistics. It is useful to perform a general health check on your system because it reports on the system as a whole. Commands such as top can be used to gain more specific information about the process operation.

When you use it for the first time during a session, the information is reported as averages since the last reboot. Further usage produces reports that are based on a sampling period that you can specify as an option. vmstat 3 4 displays values every 3 seconds for a count of four times. It might be useful to start vmstat before the application, have it direct its output to a file and later study the statistics as the application started and ran.

The basic output from this command is displayed in these sections:

processes
Shows how many processes are awaiting run time, blocked, or swapped out.
memory
Shows the amount of memory (in kilobytes) swapped, free, buffered, and cached. If the free memory is going down during certain stages of your applications execution, there might be a memory leak.
swap
Shows the kilobytes per second of memory swapped in from and swapped out to disk. Memory is swapped out to disk if not enough RAM is available to store it all. Large values here can be a hint that not enough RAM is available (although it is normal to get swapping when the application first starts).
io
Shows the number of blocks per second of memory sent to and received from block devices.
system
Displays the interrupts and the context switches per second. There is a performance penalty associated with each context switch so a high value for this section might mean that the program does not scale well.
cpu
Shows a breakdown of processor time between user time, system time, and idle time. The idle time figure shows how busy a processor is, with a low value indicating that the processor is busy. You can use this knowledge to help you understand which areas of your program are using the CPU the most.