Using 'ps' command in Linux, how to see the realtime data?

cpu, java, linux, ps

Solution

there are many tools to see the `almost` real time process state, like: `top` `htop` `dstat`

Also, in linux, you can explore system state, including `cpu information`, `process information`, `network and interface information` and so fourth under `/proc` folder. This is where all the data that tools extract from.

Problem

I found that my java web server(tomcat) used high cpu, so I used 'ps aux' to see the process infomation, like: ``` # ps aux | grep -E "PID|java" USER PID %CPU %MEM root 7533 143 39.8 ``` It showed that java took 143% cpu. Then I used 'top' command to see, the cpu usage of java process was also about 140%. After that, I took the web server offline(no access, bug process still living). Then I used top to see, java used very low cpu: ``` # top | grep -E "PID|java" PID %CPU %MEM TIME+ COMMAND 7533 0.7 39.9 455:13.81 java PID %CPU %MEM TIME+ COMMAND ``` 'vmstat' also showed that the cpu was almost idle: ``` # vmstat 1 -----cpu------ us sy id wa st 19 1 79 1 0 0 0 99 1 0 0 0 100 0 0 0 0 100 0 0 0 0 98 1 0 0 0 99 1 0 ``` Then, I used 'ps' command again, the result was: ``` #ps aux | grep -E "PID|java" USER PID %CPU %MEM root 7533 137 39.8 ``` It showed that 7533 still takes 137% cpu! After a long time, I check 'ps' again, the result is still %137... So, dose the 'ps' command show some old data? And how can I see the realtime data by 'ps'(Because I want to use 'ps -L' to see the information of thread)? Or is that just impossible?

Original source