dongxin1980 2014-01-30 16:42
浏览 40

获取JAVA PID PHP

I am currently hosting a java server program(craftbukkit), and it seems that when I try to get the RAM usage from the server program(craftbukkit), it doesn't return the actual used RAM, but rather somewhere around half of what it's using. (though it's not always exactly half, so it's impossible to estimate actual RAM usage this way).

I was wondering how I might go about getting the actual RAM used by the java process, as seen in the system monitor tool(on linux), this way I would be able to retrieve the amount of RAM used as reported to the system.

I saw an example previously using the PID of the process, but I don't know how to go about getting the PID of the process, knowing only the name.(only one java instance is running, so we don't have to worry about getting the wrong result)

Thanks ahead of time!

With ps -ef | grep "java" I get the following output

prodynamics@prodynamics:~$ ps -ef | grep "java"
1000     22292 29385 75 12:08 pts/0    00:42:19 java -Xmx3100M -Xms1024M -XX:MaxPermSize=248m -jar craftbukkit.jar
1000     23544 23443  0 13:04 pts/2    00:00:00 grep java

But with ps -eo pid | grep "java" The console returns no results at all. Though to my understanding it should return the PID.

  • 写回答

4条回答 默认 最新

  • dpxkkhu1812 2014-01-30 18:12
    关注

    I was able to succesfully get the PID with the following

    ps -eo pid,comm | grep 'java$' | awk '{print $1}' | head -1
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号