![](/img/trans.png)
[英]Error: java.io.IOException: No such file or directory in android 11
[英]java.io.IOException: error=11
我遇到了Java ProcessBuilder
一個奇怪的問題。 代碼如下所示(略微簡化)
public class Whatever implements Runnable
{
public void run(){
//someIdentifier is a randomly generated string
String in = someIdentifier + "input.txt";
String out = someIdentifier + "output.txt";
ProcessBuilder builder = new ProcessBuilder("./whateveer.sh", in, out);
try {
Process process = builder.start();
process.waitFor();
} catch (IOException e) {
log.error("Could not launch process. Command: " + builder.command(), e);
} catch (InterruptedException ex) {
log.error(ex);
}
}
}
whatever.sh讀取:
R --slave --args $1 $2 <whatever1.R >> r.log
的實例的負載Whatever
被提交到一個ExecutorService
固定大小(35)的。 應用程序的其余部分等待所有這些程序完成 - 使用CountdownLatch
實現。 在拋出以下異常之前,一切運行良好幾個小時(Scientific Linux 5.0,java版本“1.6.0_24”):
java.io.IOException: Cannot run program "./whatever.sh": java.io.IOException: error=11, Resource temporarily unavailable
at java.lang.ProcessBuilder.start(Unknown Source)
... rest of stack trace omitted...
有誰知道這意味着什么? 基於java.io.IOException: error=11
的google / bing搜索結果java.io.IOException: error=11
,它不是最常見的異常,我完全感到困惑。
我瘋狂且沒有那么受過教育的猜測是我有太多的線程試圖同時啟動同一個文件。 但是,重現問題需要數小時的CPU時間,因此我沒有嘗試使用較小的數字。
任何建議都非常感謝。
error=11
幾乎肯定是EAGAIN
錯誤代碼:
$ grep EAGAIN asm-generic/errno-base.h
#define EAGAIN 11 /* Try again */
clone(2)
系統調用記錄了EAGAIN
錯誤返回:
EAGAIN Too many processes are already running.
fork(2)
系統調用文檔兩個EAGAIN
錯誤返回:
EAGAIN fork() cannot allocate sufficient memory to copy the
parent's page tables and allocate a task structure for
the child.
EAGAIN It was not possible to create a new process because
the caller's RLIMIT_NPROC resource limit was
encountered. To exceed this limit, the process must
have either the CAP_SYS_ADMIN or the CAP_SYS_RESOURCE
capability.
如果你的內存真的那么低,幾乎肯定會在系統日志中顯示出來。 檢查dmesg(1)
輸出或/var/log/syslog
以查找有關低系統內存的任何潛在消息。 (其他事情會破裂。這似乎不太合理。)
更有可能的是,每個用戶對進程的限制或系統范圍的最大進程數都會遇到這種情況。 也許你的一個過程沒有正確收割僵屍? 通過隨時間檢查ps(1)
輸出,可以很容易地發現這一點:
while true ; do ps auxw >> ~/processes ; sleep 10 ; done
(如果在遇到麻煩之前確實需要幾個小時,也許每分鍾或十分鍾檢查一次。)
如果你沒有收獲僵屍,那么請閱讀你必須對ProcessBuilder做的任何事情來使用waitpid(2)
來收獲死去的孩子。
如果合法運行的進程多於rlimits允許的進程,則需要在bash(1)
腳本中使用ulimit
(如果以root
身份運行)或在/etc/security/limits.conf
為nproc
屬性設置更高的限制。
如果您遇到系統范圍的進程限制,則可能需要在/proc/sys/kernel/pid_max
寫入更大的值。 有關(短)詳細信息,請參閱proc(5)
。
errno 11表示“資源暫時不可用”這通常是內存問題,可以防止創建一個線程或套接字。
errno 12表示“無法分配內存”。 這是一個獲取內存失敗的直接調用內存(而不是一個需要內存的資源)
我會嘗試增加系統的交換空間,這應該避免這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.