Java 프로세스 목록
bash에서 모든 Java 프로세스를 나열하려면 어떻게해야합니까? 명령 줄이 필요합니다. 명령이 있다는 것을 알고 ps
있지만 어떤 매개 변수를 사용해야하는지 모르겠습니다.
시험:
ps aux | grep java
그리고 어떻게 타는 지 봐
최신 Java는 Java Virtual Machine 프로세스 상태 도구 "jps"와 함께 제공됩니다.
http://download.oracle.com/javase/1.5.0/docs/tooldocs/share/jps.html
예를 들면
[nsushkin@fulton support]$ jps -m
2120 Main --userdir /home/nsushkin/.netbeans/7.0 --branding nb
26546 charles.jar
17600 Jps -m
jps -lV
가장 유용합니다. pid 및 정규화 된 기본 클래스 이름 만 인쇄합니다.
2472 com.intellij.idea.Main
11111 sun.tools.jps.Jps
9030 play.server.Server
2752 org.jetbrains.idea.maven.server.RemoteMavenServer
단일 명령 pgrep 도 사용할 수 있습니다 (파이프 및 여러 명령을 사용할 필요가 없음).
pgrep -fl java
Java 7부터 시작 하여 가장 간단하고 오류 발생 가능성이 적은 jcmd
것은 JDK의 일부인 명령 을 사용하여 모든 OS에서 동일한 방식으로 작동하도록하는 것입니다.
예:
> jcmd
5485 sun.tools.jcmd.JCmd
2125 MyProgram
jcmd
실행중인 JVM (Java Virtual Machine)에 진단 명령 요청을 보낼 수 있습니다.
사용 방법에jcmd
대한 자세한 내용 .
이것은 리눅스 환경에서 실행중인 모든 자바 프로세스를 반환합니다. 그런 다음 프로세스 ID를 사용하여 프로세스를 종료 할 수 있습니다.
ps -e|grep java
더 나은 출력 형식을 보려면 다음 명령을 확인하십시오.
ps -fC java
ps aux | grep java
또는
$ ps -fea|grep -i java
단순히 Java 프로세스를 나열하려면 다음을 사용하십시오.
ps -A | grep java
pgrep -l java
ps -ef | grep java
특정 Java 클래스가 실행되고 있는지 알고 싶을 때 다음 명령 줄을 사용합니다.
ps ww -f -C java | grep "fully.qualified.name.of.class"
OS 측보기에서 프로세스의 명령 이름은 "java"입니다. "ww"옵션은 열의 최대 문자를 넓히므로 관련 클래스의 FQN을 grep 할 수 있습니다.
ps axuwww | grep java | grep -v grep
위의 것입니다
- 긴 줄이있는 모든 프로세스 표시 (인수 : www)
- 필터 (grep)는 java라는 단어를 포함하는 행만
- filter out the line "grep java" :)
(btw, this example is not the effective one, but simple to remember) ;)
you can pipe the above to another commands, for example:
ps axuwww | grep java | grep -v grep | sed '.....' | while read something
do
something_another $something
done
etc...
jps & jcmd wasn't showing me any results when I tried it using using openjdk-1.8 on redhat linux. But even if it did it only shows processes under the current user which doesn't work in my case. Using the ps|grep is what I ended up doing but the class path for some java apps can be extremely long which makes results illegible so I used sed to remove it. This is a bit rough still but removes everything except: PID, User, java-class/jar, args.
ps -o pid,user,cmd -C java | sed -e 's/\([0-9]\+ *[^ ]*\) *[^ ]* *\([^$]*\)/\1 \2/' -e 's/-c[^ ]* [^ ]* \|-[^ ]* //g'
Results look something like:
PID USER CMD
11251 userb org.apache.zookeeper.server.quorum.QuorumPeerMain ../config/zookeeper.properties
19574 userb com.intellij.idea.Main
28807 root org.apache.nifi.bootstrap.RunNiFi run
28829 root org.apache.nifi.NiFi
An alternative on windows to list all processes is:
WMIC path win32_process where "Caption='java.exe'" get ProcessId,Commandline
But that is going to need some parsing to make it more legible.
There's a lot of ways of doing this. You can use java.lang.ProcessBuilder
and "pgrep" to get the process id (PID) with something like: pgrep -fl java | awk {'print $1'}
. Or, if you are running under Linux, you can query the /proc
directory.
I know, this seems horrible, and non portable, and even poorly implemented, I agree. But because Java actually runs in a VM, for some absurd reason that I can't really figure out after more then 15 years working the JDK, is why it isn't possible to see things outside the JVM space, it's really ridiculous with you think about it. You can do everything else, even fork
and join
child processes (those were an horrible way of multitasking when the world didn't know about threads or pthreads, what a hell! what's going in on with Java?! :).
This will give an immense discussion I know, but anyways, there's a very good API that I already used in my projects and it's stable enough (it's OSS so you still need to stress test every version you use before really trusting the API): https://github.com/jezhumble/javasysmon
JavaDoc: http://jezhumble.github.io/javasysmon/, search for the class com.jezhumble.javasysmon.OsProcess
, she will do the trick. Hope it helped, best of luck.
ps -eaf | grep [j]ava
It's better since it will only show you the active processes not including this command that also got java string the []
does the trick
I use this (good on Debian 8): alias psj='ps --no-headers -ww -C java -o pid,user,start_time,command'
To know the list of java running on the linux machine. ps -e | grep java
참고URL : https://stackoverflow.com/questions/6283167/list-of-java-processes
'Programing' 카테고리의 다른 글
Java에서 창을 중앙에 배치하는 방법은 무엇입니까? (0) | 2020.08.12 |
---|---|
신속하게 배경에 흐림 효과 추가 (0) | 2020.08.12 |
자바에서 문자열을 16 진수로 변환 (0) | 2020.08.12 |
foreach 루프에서 배열 요소를 어떻게 제거합니까? (0) | 2020.07.23 |
한 캔버스의 내용을 다른 캔버스에 로컬로 복사하는 방법 (0) | 2020.07.23 |