2016-07-21 73 views
0

首先對不起我的英文不好。Android:Android kill tcpdump進程

我在Android Studio中開發了一個應用程序。它調用tcpdump(Process process = Runtime.getRuntime()。exec(「su -c tcpdump -s 0 -v -w /sdcard/capture.pcap」);)。最初它能正常工作。但是,tcpdump進程突然中斷。有人會告訴我爲什麼嗎?

謝謝

回答

0

它可能會告訴你,爲什麼在標準錯誤:

final Process p = Runtime.getRuntime().exec(tcpdumpCommand); 
final BufferedReader reader = new BufferedReader(
    new InputStreamReader(p.getErrorStream())); 
(new Thread() { 
    public void run() { 
    while ((line = reader.readLine()) != null) { 
     Log.d("tcpdump", "stderr: " + line); 
    } 
    Log.d("tcpdump", "end of stderr"); 
    } 
}).start(); 

...然後查看logcat中。或者試試getOutputStream()(用於標準輸出)而不是getErrorStream()

此外,如果tcpdump成功捕獲流量然後突然停止,一個可能的原因是您填充了SD卡。