2012-06-04 39 views
1

我想知道是否有人確定ProcessBuilder/Runtime.exec()是否在JVM內存空間內執行,或者它是否使用完全獨立的系統內存並以某種方式將輸出發送給Java。我找不到關於此主題的任何文檔。Java ProcessBuilder內存

我認爲這是前者由於安全問題和能夠讀取輸出,但我想絕對確定。

回答

5

新進程在啓動它的Java進程外運行。內存分配到新進程由操作系統管理,作爲process management的一部分。

Java類ProcessBuilder提供了一個用於啓動和與新進程通信的接口,在Java進程內運行。

+0

明白了。感謝您的簡潔回答! – kevin948

0

似乎很清楚,exec會爲那些不熟悉操作系統術語的人啓動一個新進程或程序。這就是爲什麼它具有輸入輸出設施,設置環境的能力以及等待外部程序返回的能力。

The first line of the javadoc says it all

Executes the specified string command in a separate process. 

The command argument is parsed into tokens and then executed as a command in a 
separate process. The token parsing is done by a StringTokenizer created by the 
call: 

    new StringTokenizer(command) 


with no further modifications of the character categories. This method has exactly 
the same effect as exec(command, null). 
0

從Java SE的concurrency參考,據說:

進程具有獨立的執行環境。進程 通常具有完整的私有基本運行時資源集合;特別是,每個進程都有自己的內存空間。

如果您對內部感興趣,請從openJDK中檢查UNIXProcess類。